Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/basic_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: basic-check

on:
push:
branches:
- master
pull_request:
branches:
- '**'

jobs:
check:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20.9'
cache: true

- name: install deps
run: |
sudo apt-get update
sudo apt-get -o Acquire::Retries=3 install make gcc git curl wget -y

- name: Build
env:
GOPROXY: "https://proxy.golang.org,direct"
GO111MODULE: "on"
run: |
make build

- name: Lint
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -d -b $(go env GOPATH)/bin v1.55.1
golangci-lint run --timeout 10m

- name: Detect changes
run: |
git status --porcelain
test -z "$(git status --porcelain)"
46 changes: 46 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: basic-check

on:
push:
branches:
- master
pull_request:
branches:
- '**'

jobs:
test:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20.9'
cache: true

- name: install deps
run: |
sudo apt-get update
sudo apt-get -o Acquire::Retries=3 install make gcc git curl wget -y

- name: Build
env:
GOPROXY: "https://proxy.golang.org,direct"
GO111MODULE: "on"
run: |
make build

- name: Test
run: |
go test -coverpkg=./... -coverprofile=coverage.txt -covermode=atomic -timeout=30m -parallel=4 -v ./...

- name: Upload
uses: codecov/codecov-action@v3
with:
token:
files: ./coverage.txt
name: jzfs
fail_ci_if_error: true
verbose: true
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jzfs
# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Test coverage file
coverage.txt

# Dependency directories (remove the comment below to include it)
# vendor/
Expand Down
29 changes: 29 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
linters:
disable-all: true
enable:
- gofmt
- govet
- misspell
- goconst
- revive
- errcheck
- unconvert
- staticcheck
- unused
- stylecheck
- gosimple
- goimports
issues:
exclude:
- "should have( a package)? comment"

exclude-rules:
exclude-use-default: false

linters-settings:
goconst:
min-occurrences: 6

run:
skip-dirs:
skip-files:
7 changes: 4 additions & 3 deletions api/api_impl/common.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package api_impl
package apiimpl

import (
"net/http"

"github.com/jiaozifs/jiaozifs/api"
"github.com/jiaozifs/jiaozifs/version"
"go.uber.org/fx"
"net/http"
)

var _ api.ServerInterface = (*APIController)(nil)
Expand All @@ -13,7 +14,7 @@ type APIController struct {
fx.In
}

func (A APIController) GetVersion(w *api.JiaozifsResponse, r *http.Request) {
func (A APIController) GetVersion(w *api.JiaozifsResponse, _ *http.Request) {
swagger, err := api.GetSwagger()
if err != nil {
w.RespError(err)
Expand Down
11 changes: 7 additions & 4 deletions api/api_impl/server.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package api_impl
package apiimpl

import (
"context"
"errors"

"net"
"net/http"

"net/url"

"github.com/getkin/kin-openapi/openapi3filter"
"github.com/go-chi/chi/v5"
"github.com/go-chi/cors"
Expand All @@ -11,9 +17,6 @@ import (
"github.com/jiaozifs/jiaozifs/config"
middleware "github.com/oapi-codegen/nethttp-middleware"
"go.uber.org/fx"
"net"
"net/http"
"net/url"
)

var log = logging.Logger("rpc")
Expand Down
22 changes: 0 additions & 22 deletions api/api_impl/utils.go

This file was deleted.

2 changes: 1 addition & 1 deletion api/custom_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ func (response *JiaozifsResponse) RespJSON(v interface{}) {

func (response *JiaozifsResponse) RespError(err error) {
response.WriteHeader(http.StatusOK)
response.Write([]byte(err.Error()))
_, _ = response.Write([]byte(err.Error()))
}
2 changes: 1 addition & 1 deletion api/docs.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package apigen provides generated code for our OpenAPI
// Package api provides generated code for our OpenAPI
package api

//go:generate go run github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen -package api -templates ./tmpls -generate "types,client,chi-server,spec" -o jiaozifs.gen.go ./swagger.yml
4 changes: 3 additions & 1 deletion api/jiaozifs.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 5 additions & 8 deletions cmd/daemon.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"context"

logging "github.com/ipfs/go-log/v2"
"github.com/jiaozifs/jiaozifs/api/api_impl"
apiImpl "github.com/jiaozifs/jiaozifs/api/api_impl"
"github.com/jiaozifs/jiaozifs/config"
"github.com/jiaozifs/jiaozifs/fx_opt"
"github.com/jiaozifs/jiaozifs/models"
Expand Down Expand Up @@ -48,7 +46,7 @@ var daemonCmd = &cobra.Command{
fx_opt.Override(fx_opt.NextInvoke(), migrations.MigrateDatabase),
fx_opt.Override(new(*models.IUserRepo), models.NewUserRepo),
//api
fx_opt.Override(fx_opt.NextInvoke(), api_impl.SetupAPI),
fx_opt.Override(fx_opt.NextInvoke(), apiImpl.SetupAPI),
)
if err != nil {
return err
Expand All @@ -59,7 +57,6 @@ var daemonCmd = &cobra.Command{
<-shutdown
log.Info("graceful shutdown")
return stop(cmd.Context())
return nil
},
}

Expand All @@ -68,6 +65,6 @@ func init() {
daemonCmd.Flags().String("db", "", "pg connection string eg. postgres://user:pass@localhost:5432/jiaozifs?sslmode=disable")
daemonCmd.Flags().String("log-level", "INFO", "set log level eg. DEBUG INFO ERROR")

viper.BindPFlag("database.connection", daemonCmd.Flags().Lookup("db"))
viper.BindPFlag("log.level", daemonCmd.Flags().Lookup("log-level"))
_ = viper.BindPFlag("database.connection", daemonCmd.Flags().Lookup("db"))
_ = viper.BindPFlag("log.level", daemonCmd.Flags().Lookup("log-level"))
}
9 changes: 3 additions & 6 deletions cmd/init.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
Expand All @@ -14,9 +11,9 @@ var initCmd = &cobra.Command{
Use: "init",
Short: "init jiaozifs ",
Long: `create default config file for jiaoozifs`,
PreRun: func(cmd *cobra.Command, args []string) {
//provent duplicate bind flag with daemon
viper.BindPFlag("database.connection", cmd.Flags().Lookup("db"))
PreRunE: func(cmd *cobra.Command, args []string) error {
//protect duplicate bind flag with daemon
return viper.BindPFlag("database.connection", cmd.Flags().Lookup("db"))
},
RunE: func(cmd *cobra.Command, args []string) error {
return config.InitConfig()
Expand Down
8 changes: 3 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
/*
Copyright © 2023 githun.com/jiaozifs/jiaozifs
*/
package cmd

import (
"os"

"github.com/spf13/cobra"
"github.com/spf13/viper"
"os"
)

var cfgFile string
Expand All @@ -29,5 +27,5 @@ func Execute() {

func init() {
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.jiaozifs/config.yaml)")
viper.BindPFlag("config", rootCmd.Flags().Lookup("config"))
_ = viper.BindPFlag("config", rootCmd.Flags().Lookup("config"))
}
8 changes: 3 additions & 5 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"fmt"

"github.com/jiaozifs/jiaozifs/api"
"github.com/jiaozifs/jiaozifs/api/api_impl"
apiimpl "github.com/jiaozifs/jiaozifs/api/api_impl"
"github.com/jiaozifs/jiaozifs/config"
"github.com/jiaozifs/jiaozifs/version"
"github.com/spf13/cobra"
Expand All @@ -30,7 +28,7 @@ var versionCmd = &cobra.Command{
if err != nil {
return err
}
client, err := api.NewClient(cfg.API.Listen + api_impl.APIV1Prefix)
client, err := api.NewClient(cfg.API.Listen + apiimpl.APIV1Prefix)
if err != nil {
return err
}
Expand Down
9 changes: 4 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ package config

import (
"fmt"
logging "github.com/ipfs/go-log/v2"

"os"
"path"

ms "github.com/mitchellh/mapstructure"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"os"
"path"
)

var log = logging.Logger("log")

type Config struct {
Path string `mapstructure:"config"`
Log LogConfig `mapstructure:"log"`
Expand Down
1 change: 1 addition & 0 deletions models/migrations/20210505110026_init_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package migrations

import (
"context"

"github.com/jiaozifs/jiaozifs/models"
"github.com/uptrace/bun"
)
Expand Down
1 change: 1 addition & 0 deletions models/migrations/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package migrations

import (
"context"

"github.com/uptrace/bun"
"github.com/uptrace/bun/migrate"
)
Expand Down
1 change: 1 addition & 0 deletions models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package models
import (
"context"
"database/sql"

"github.com/jiaozifs/jiaozifs/config"
"github.com/uptrace/bun"
"github.com/uptrace/bun/dialect/pgdialect"
Expand Down
Loading