26
.github/workflows/checks.yml
vendored
26
.github/workflows/checks.yml
vendored
@@ -26,10 +26,10 @@ jobs:
|
|||||||
--health-timeout 5s
|
--health-timeout 5s
|
||||||
--health-retries 5
|
--health-retries 5
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- uses: actions/setup-go@v2
|
- uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: ${{ env.GO_VERSION }}
|
go-version: ${{ env.GO_VERSION }}
|
||||||
- run: go mod download
|
- run: go mod download
|
||||||
@@ -42,14 +42,32 @@ jobs:
|
|||||||
PGPASSWORD: postgres
|
PGPASSWORD: postgres
|
||||||
PGDATABASE: booktown
|
PGDATABASE: booktown
|
||||||
|
|
||||||
|
lint:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 10
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: ${{ env.GO_VERSION }}
|
||||||
|
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: golangci-lint
|
||||||
|
uses: golangci/golangci-lint-action@v3
|
||||||
|
with:
|
||||||
|
version: v1.50.1
|
||||||
|
|
||||||
fmt:
|
fmt:
|
||||||
name: fmt
|
name: fmt
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- uses: actions/setup-go@v2
|
- uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: ${{ env.GO_VERSION }}
|
go-version: ${{ env.GO_VERSION }}
|
||||||
- run: go mod download
|
- run: go mod download
|
||||||
|
|||||||
3
Makefile
3
Makefile
@@ -28,6 +28,9 @@ test-all:
|
|||||||
@./script/test_all.sh
|
@./script/test_all.sh
|
||||||
@./script/test_cockroach.sh
|
@./script/test_cockroach.sh
|
||||||
|
|
||||||
|
lint:
|
||||||
|
golangci-lint run
|
||||||
|
|
||||||
dev:
|
dev:
|
||||||
go build
|
go build
|
||||||
@echo "You can now execute ./pgweb"
|
@echo "You can now execute ./pgweb"
|
||||||
|
|||||||
@@ -533,7 +533,7 @@ func DataExport(c *gin.Context) {
|
|||||||
if dump.Table != "" {
|
if dump.Table != "" {
|
||||||
filename = filename + "_" + dump.Table
|
filename = filename + "_" + dump.Table
|
||||||
}
|
}
|
||||||
reg := regexp.MustCompile("[^._\\w]+")
|
reg := regexp.MustCompile(`[^._\\w]+`)
|
||||||
cleanFilename := reg.ReplaceAllString(filename, "")
|
cleanFilename := reg.ReplaceAllString(filename, "")
|
||||||
|
|
||||||
c.Header(
|
c.Header(
|
||||||
|
|||||||
@@ -139,10 +139,17 @@ func startTestBackend(ctx context.Context, listenAddr string) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
server := &http.Server{Addr: listenAddr, Handler: router}
|
server := &http.Server{Addr: listenAddr, Handler: router}
|
||||||
go server.ListenAndServe()
|
go mustStartServer(server)
|
||||||
|
|
||||||
select {
|
<-ctx.Done()
|
||||||
case <-ctx.Done():
|
if err := server.Shutdown(context.Background()); err != nil && err != http.ErrServerClosed {
|
||||||
server.Shutdown(context.Background())
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func mustStartServer(server *http.Server) {
|
||||||
|
err := server.ListenAndServe()
|
||||||
|
if err != nil && err != http.ErrServerClosed {
|
||||||
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package bookmarks
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ func (b Bookmark) ConvertToOptions() command.Options {
|
|||||||
func readServerConfig(path string) (Bookmark, error) {
|
func readServerConfig(path string) (Bookmark, error) {
|
||||||
bookmark := Bookmark{}
|
bookmark := Bookmark{}
|
||||||
|
|
||||||
buff, err := ioutil.ReadFile(path)
|
buff, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return bookmark, err
|
return bookmark, err
|
||||||
}
|
}
|
||||||
@@ -100,7 +100,7 @@ func Path(overrideDir string) string {
|
|||||||
func ReadAll(path string) (map[string]Bookmark, error) {
|
func ReadAll(path string) (map[string]Bookmark, error) {
|
||||||
results := map[string]Bookmark{}
|
results := map[string]Bookmark{}
|
||||||
|
|
||||||
files, err := ioutil.ReadDir(path)
|
files, err := os.ReadDir(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return results, err
|
return results, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"os/signal"
|
"os/signal"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/jessevdk/go-flags"
|
"github.com/jessevdk/go-flags"
|
||||||
@@ -203,7 +204,7 @@ func startServer() {
|
|||||||
|
|
||||||
func handleSignals() {
|
func handleSignals() {
|
||||||
c := make(chan os.Signal, 1)
|
c := make(chan os.Signal, 1)
|
||||||
signal.Notify(c, os.Interrupt, os.Kill)
|
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||||
<-c
|
<-c
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,7 +221,10 @@ func openPage() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
exec.Command("open", url).Output()
|
_, err = exec.Command("open", url).Output()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Unable to auto-open pgweb URL:", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Run() {
|
func Run() {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ var (
|
|||||||
|
|
||||||
func mapKeys(data map[string]*Objects) []string {
|
func mapKeys(data map[string]*Objects) []string {
|
||||||
result := []string{}
|
result := []string{}
|
||||||
for k, _ := range data {
|
for k := range data {
|
||||||
result = append(result, k)
|
result = append(result, k)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
@@ -421,8 +421,10 @@ func testHistoryUniqueness(t *testing.T) {
|
|||||||
url := fmt.Sprintf("postgres://%s@%s:%s/%s?sslmode=disable", serverUser, serverHost, serverPort, serverDatabase)
|
url := fmt.Sprintf("postgres://%s@%s:%s/%s?sslmode=disable", serverUser, serverHost, serverPort, serverDatabase)
|
||||||
client, _ := NewFromUrl(url, nil)
|
client, _ := NewFromUrl(url, nil)
|
||||||
|
|
||||||
client.Query("SELECT * FROM books WHERE id = 1")
|
for i := 0; i < 3; i++ {
|
||||||
client.Query("SELECT * FROM books WHERE id = 1")
|
_, err := client.Query("SELECT * FROM books WHERE id = 1")
|
||||||
|
assert.NoError(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
assert.Equal(t, 1, len(client.History))
|
assert.Equal(t, 1, len(client.History))
|
||||||
assert.Equal(t, "SELECT * FROM books WHERE id = 1", client.History[0].Query)
|
assert.Equal(t, "SELECT * FROM books WHERE id = 1", client.History[0].Query)
|
||||||
@@ -445,7 +447,8 @@ func testReadOnlyMode(t *testing.T) {
|
|||||||
assert.Error(t, err, "query contains keywords not allowed in read-only mode")
|
assert.Error(t, err, "query contains keywords not allowed in read-only mode")
|
||||||
|
|
||||||
// Turn off guard
|
// Turn off guard
|
||||||
client.db.Exec("SET default_transaction_read_only=off;")
|
_, err = client.db.Exec("SET default_transaction_read_only=off;")
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
_, err = client.Query("\nCREATE TABLE foobar(id integer);\n")
|
_, err = client.Query("\nCREATE TABLE foobar(id integer);\n")
|
||||||
assert.NotNil(t, err)
|
assert.NotNil(t, err)
|
||||||
@@ -471,6 +474,7 @@ func TestAll(t *testing.T) {
|
|||||||
setupClient()
|
setupClient()
|
||||||
|
|
||||||
testNewClientFromUrl(t)
|
testNewClientFromUrl(t)
|
||||||
|
testNewClientFromUrl2(t)
|
||||||
testClientIdleTime(t)
|
testClientIdleTime(t)
|
||||||
testTest(t)
|
testTest(t)
|
||||||
testInfo(t)
|
testInfo(t)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/csv"
|
"encoding/csv"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"math"
|
"math"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
@@ -88,7 +89,9 @@ func (res *Result) CSV() []byte {
|
|||||||
buff := &bytes.Buffer{}
|
buff := &bytes.Buffer{}
|
||||||
writer := csv.NewWriter(buff)
|
writer := csv.NewWriter(buff)
|
||||||
|
|
||||||
writer.Write(res.Columns)
|
if err := writer.Write(res.Columns); err != nil {
|
||||||
|
log.Printf("result csv write error: %v\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
for _, row := range res.Rows {
|
for _, row := range res.Rows {
|
||||||
record := make([]string, len(res.Columns))
|
record := make([]string, len(res.Columns))
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -54,7 +53,7 @@ func fileExists(path string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func parsePrivateKey(keyPath string, keyPass string) (ssh.Signer, error) {
|
func parsePrivateKey(keyPath string, keyPass string) (ssh.Signer, error) {
|
||||||
buff, err := ioutil.ReadFile(keyPath)
|
buff, err := os.ReadFile(keyPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,10 +11,7 @@ import (
|
|||||||
func IsPortAvailable(port int) bool {
|
func IsPortAvailable(port int) bool {
|
||||||
conn, err := net.Dial("tcp", fmt.Sprintf("127.0.0.1:%v", port))
|
conn, err := net.Dial("tcp", fmt.Sprintf("127.0.0.1:%v", port))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if strings.Index(err.Error(), "connection refused") > 0 {
|
return strings.Index(err.Error(), "connection refused") > 0
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
conn.Close()
|
conn.Close()
|
||||||
|
|||||||
Reference in New Issue
Block a user