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