diff --git a/.github/workflows/test-go.yaml b/.github/workflows/test-go.yaml new file mode 100644 index 00000000..c1e75a1f --- /dev/null +++ b/.github/workflows/test-go.yaml @@ -0,0 +1,31 @@ +# A basic workflow for Go +name: test-go +on: [push] +defaults: + run: + shell: bash -ieo pipefail {0} +jobs: + test: + name: golang test & build + # Must run on github hosted runners + runs-on: [ubuntu-20.04] + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: '1.21.3' # The Go version to download (if necessary) and use. + - run: go test ./... + working-directory: app + - run: go build ./... + working-directory: app + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version + # https://github.com/golangci/golangci-lint/releases + version: v1.57 + # These options work around the errors in this issue + # https://github.com/golangci/golangci-lint-action/issues/244 + skip-pkg-cache: true + skip-build-cache: true + working-directory: app \ No newline at end of file diff --git a/app/.golangci.yaml b/app/.golangci.yaml new file mode 100644 index 00000000..9b55ad7c --- /dev/null +++ b/app/.golangci.yaml @@ -0,0 +1,8 @@ +linters: + enable: + - gofmt + - goimports + - staticcheck +run: + # Use skip-dirs if there are any directors that must be skipped + skip-dirs: [] \ No newline at end of file diff --git a/app/cmd/assets.go b/app/cmd/assets.go index 7cf138be..a2dd169a 100644 --- a/app/cmd/assets.go +++ b/app/cmd/assets.go @@ -3,11 +3,12 @@ package cmd import ( "context" "fmt" + "os" + "github.com/jlewi/foyle/app/pkg/application" "github.com/jlewi/foyle/app/pkg/assets" "github.com/jlewi/monogo/helpers" "github.com/spf13/cobra" - "os" ) // NewAssetsCmd returns a command to download the assets diff --git a/app/cmd/root.go b/app/cmd/root.go index 3a03ff11..92301ba1 100644 --- a/app/cmd/root.go +++ b/app/cmd/root.go @@ -2,9 +2,10 @@ package cmd import ( "fmt" + "os" + "github.com/jlewi/foyle/app/pkg/config" "github.com/spf13/cobra" - "os" ) const ( diff --git a/app/cmd/serve.go b/app/cmd/serve.go index 2f5e0be7..3918d4fb 100644 --- a/app/cmd/serve.go +++ b/app/cmd/serve.go @@ -2,9 +2,10 @@ package cmd import ( "fmt" - "github.com/jlewi/foyle/app/pkg/application" "os" + "github.com/jlewi/foyle/app/pkg/application" + "github.com/jlewi/monogo/helpers" "github.com/spf13/cobra" ) diff --git a/app/pkg/application/app.go b/app/pkg/application/app.go index 48debe60..7cc01158 100644 --- a/app/pkg/application/app.go +++ b/app/pkg/application/app.go @@ -2,15 +2,16 @@ package application import ( "fmt" + "io" + "os" + "strings" + "github.com/go-logr/zapr" "github.com/jlewi/foyle/app/pkg/config" "github.com/jlewi/foyle/app/pkg/server" "github.com/pkg/errors" "github.com/spf13/cobra" "go.uber.org/zap" - "io" - "os" - "strings" ) // App is a struct to hold values needed across all commands. diff --git a/app/pkg/assets/manager.go b/app/pkg/assets/manager.go index 2965cfbd..c7bbc2cb 100644 --- a/app/pkg/assets/manager.go +++ b/app/pkg/assets/manager.go @@ -3,6 +3,11 @@ package assets import ( "archive/tar" "context" + "io" + "net/url" + "os" + "path/filepath" + "github.com/go-logr/zapr" "github.com/jlewi/foyle/app/pkg/config" "github.com/jlewi/foyle/app/pkg/logs" @@ -10,10 +15,6 @@ import ( "github.com/jlewi/hydros/pkg/images" "github.com/pkg/errors" "go.uber.org/zap" - "io" - "net/url" - "os" - "path/filepath" ) const ( @@ -44,7 +45,7 @@ func (m *Manager) Download(ctx context.Context) error { log := logs.FromContext(ctx) // Map from the name of the asset to the source of the location assets := map[string]asset{ - vscode: asset{ + vscode: { source: m.config.Assets.VSCode.URI, stripPrefix: "assets", }, diff --git a/app/pkg/assets/manager_test.go b/app/pkg/assets/manager_test.go index c17c9bd3..929074fc 100644 --- a/app/pkg/assets/manager_test.go +++ b/app/pkg/assets/manager_test.go @@ -2,10 +2,11 @@ package assets import ( "context" - "github.com/jlewi/foyle/app/pkg/config" - "go.uber.org/zap" "os" "testing" + + "github.com/jlewi/foyle/app/pkg/config" + "go.uber.org/zap" ) func Test_Download(t *testing.T) { diff --git a/app/pkg/config/config.go b/app/pkg/config/config.go index f167b8f2..a68ff8be 100644 --- a/app/pkg/config/config.go +++ b/app/pkg/config/config.go @@ -2,17 +2,18 @@ package config import ( "fmt" + "io/fs" + "os" + "os/user" + "path/filepath" + "strings" + "github.com/go-logr/zapr" "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/spf13/viper" "go.uber.org/zap" "gopkg.in/yaml.v3" - "io/fs" - "os" - "os/user" - "path/filepath" - "strings" ) // Note: The application uses viper for configuration management. Viper merges configurations from various sources diff --git a/app/pkg/server/extensions.go b/app/pkg/server/extensions.go index f17cb54b..1bc9c5dd 100644 --- a/app/pkg/server/extensions.go +++ b/app/pkg/server/extensions.go @@ -1,11 +1,12 @@ package server import ( + "os" + "path/filepath" + "github.com/go-logr/zapr" "github.com/pkg/errors" "go.uber.org/zap" - "os" - "path/filepath" ) // findExtensionsInDir returns a list of all the extensions diff --git a/app/pkg/server/server.go b/app/pkg/server/server.go index 17aedf01..1b839446 100644 --- a/app/pkg/server/server.go +++ b/app/pkg/server/server.go @@ -3,11 +3,6 @@ package server import ( "encoding/json" "fmt" - "github.com/gin-gonic/gin" - "github.com/go-logr/zapr" - "github.com/jlewi/foyle/app/pkg/config" - "github.com/pkg/errors" - "go.uber.org/zap" "html/template" "log" "net/http" @@ -16,6 +11,12 @@ import ( "path/filepath" "strings" "syscall" + + "github.com/gin-gonic/gin" + "github.com/go-logr/zapr" + "github.com/jlewi/foyle/app/pkg/config" + "github.com/pkg/errors" + "go.uber.org/zap" ) // Server is the main application server for foyle @@ -181,6 +182,7 @@ func (s *Server) setHTMLTemplates(router *gin.Engine) error { func (s *Server) Run() error { address := fmt.Sprintf("%s:%d", s.config.Server.BindAddress, s.config.Server.HttpPort) log.Print("Server listening on http://" + address) + trapInterrupt() if err := http.ListenAndServe(address, s.engine); err != nil { log.Fatalf("There was an error with the http server: %v", err) }