Skip to content

Commit

Permalink
chore: adjust directory structure of api (#1108)
Browse files Browse the repository at this point in the history
chore: adjust directory structure of api
  • Loading branch information
gxthrj authored Dec 25, 2020
1 parent 78b4031 commit cc9eb35
Show file tree
Hide file tree
Showing 35 changed files with 61 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/backend-unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
export GO111MOUDULE=on
export APISIX_CONF_PATH=$PWD/conf
sed -i 's/9000/8088/' conf/conf.yaml
go build -o ./manager-api
go build -o ./manager-api ./cmd/manager
./manager-api > ./api.log 2>&1 &
sleep 2
cat ./api.log
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/frontend-e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:

- name: Start manager-api
working-directory: ./api
run: nohup go run . &
run: nohup go run ./cmd/manager &

- name: Install front-end dependencies
run: yarn install
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ RUN wget https://github.com/api7/dag-to-lua/archive/v1.1.tar.gz -O /tmp/v1.1.tar
RUN if [ "$ENABLE_PROXY" = "true" ] ; then go env -w GOPROXY=https://goproxy.io,direct ; fi

RUN go env -w GO111MODULE=on \
&& CGO_ENABLED=0 go build -o ../output/manager-api .
&& CGO_ENABLED=0 go build -o ../output/manager-api ./cmd/manager

FROM node:14-alpine as fe-builder

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ api-test: api-default
### api-run: Run the manager-api
.PHONY: api-run
api-run: api-default
cd api/ && go run .
cd api/ && go run ./cmd/manager

### api-stop: Stop the manager-api
api-stop:
Expand Down
23 changes: 23 additions & 0 deletions api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,26 @@ This is a backend project which the dashboard depends on, implemented by Golang.
## Installation

[Please refer to the doc](../README.md)

## Project structure

```text
├── README.md
├── VERSION
├── build-tools
├── build.sh
├── cmd
├── conf
├── entry.sh
├── go.mod
├── go.sum
├── internal
├── run.sh
└── test
```

1. The `cmd` directory is the project entrance.
2. The `internal` directory contains the main logic of manager-api.
3. The `conf` directory contains the default configuration file.
4. The `test` directory contains E2E test cases.

2 changes: 1 addition & 1 deletion api/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ if [[ ! -f "dag-to-lua-1.1/lib/dag-to-lua.lua" ]]; then
fi

# build
cd ./api && go build -o ../output/manager-api -ldflags "-X github.com/apisix/manager-api/cmd.Version=${VERSION}" . && cd ..
cd ./api && go build -o ../output/manager-api -ldflags "-X github.com/apisix/manager-api/cmd.Version=${VERSION}" ./cmd/manager && cd ..

cp ./api/conf/schema.json ./output/conf/schema.json
cp ./api/conf/conf.yaml ./output/conf/conf.yaml
Expand Down
File renamed without changes.
10 changes: 4 additions & 6 deletions api/cmd/managerapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,15 @@ import (
"syscall"
"time"

"github.com/shiningrush/droplet"
"github.com/spf13/cobra"

"github.com/apisix/manager-api/conf"
"github.com/apisix/manager-api/internal"
"github.com/apisix/manager-api/internal/conf"
"github.com/apisix/manager-api/internal/core/storage"
"github.com/apisix/manager-api/internal/core/store"
"github.com/apisix/manager-api/internal/handler"
"github.com/apisix/manager-api/internal/log"
"github.com/apisix/manager-api/internal/utils"
"github.com/apisix/manager-api/log"
"github.com/shiningrush/droplet"
"github.com/spf13/cobra"
)

var Version string
Expand All @@ -47,7 +46,6 @@ func printInfo() {
fmt.Fprintf(os.Stdout, "%-8s: %s\n\n", "Logfile", conf.ErrorLogPath)
}


// NewManagerAPICommand creates the manager-api command.
func NewManagerAPICommand() *cobra.Command {
cmd := &cobra.Command{
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion api/internal/core/entity/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"net"
"strconv"

"github.com/apisix/manager-api/log"
"github.com/apisix/manager-api/internal/log"
)

func mapKV2Node(key string, val float64) (*Node, error) {
Expand Down
4 changes: 2 additions & 2 deletions api/internal/core/storage/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import (

"go.etcd.io/etcd/clientv3"

"github.com/apisix/manager-api/conf"
"github.com/apisix/manager-api/internal/conf"
"github.com/apisix/manager-api/internal/log"
"github.com/apisix/manager-api/internal/utils"
"github.com/apisix/manager-api/log"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion api/internal/core/store/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package store

import (
"github.com/apisix/manager-api/internal/core/entity"
"github.com/apisix/manager-api/log"
"github.com/apisix/manager-api/internal/log"
)

type Query struct {
Expand Down
2 changes: 1 addition & 1 deletion api/internal/core/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import (

"github.com/apisix/manager-api/internal/core/entity"
"github.com/apisix/manager-api/internal/core/storage"
"github.com/apisix/manager-api/internal/log"
"github.com/apisix/manager-api/internal/utils"
"github.com/apisix/manager-api/log"
)

type Interface interface {
Expand Down
2 changes: 1 addition & 1 deletion api/internal/core/store/storehub.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"reflect"

"github.com/apisix/manager-api/internal/core/entity"
"github.com/apisix/manager-api/internal/log"
"github.com/apisix/manager-api/internal/utils"
"github.com/apisix/manager-api/log"
)

type HubKey string
Expand Down
4 changes: 2 additions & 2 deletions api/internal/core/store/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import (
"github.com/xeipuuv/gojsonschema"
"go.uber.org/zap/buffer"

"github.com/apisix/manager-api/conf"
"github.com/apisix/manager-api/internal/conf"
"github.com/apisix/manager-api/internal/core/entity"
"github.com/apisix/manager-api/log"
"github.com/apisix/manager-api/internal/log"
)

type Validator interface {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ import (

"github.com/dgrijalva/jwt-go"
"github.com/gin-gonic/gin"

"github.com/apisix/manager-api/conf"
"github.com/apisix/manager-api/log"
"github.com/apisix/manager-api/internal/conf"
"github.com/apisix/manager-api/internal/log"
)

func Authentication() gin.HandlerFunc {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"

"github.com/apisix/manager-api/log"
"github.com/apisix/manager-api/internal/log"
)

func performRequest(r http.Handler, method, path string) *httptest.ResponseRecorder {
Expand Down
2 changes: 1 addition & 1 deletion api/filter/recover.go → api/internal/filter/recover.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
"runtime"
"time"

"github.com/apisix/manager-api/log"
"github.com/gin-gonic/gin"
"github.com/apisix/manager-api/internal/log"
)

var (
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion api/filter/schema.go → api/internal/filter/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import (

"github.com/apisix/manager-api/internal/core/entity"
"github.com/apisix/manager-api/internal/core/store"
"github.com/apisix/manager-api/internal/log"
"github.com/apisix/manager-api/internal/utils/consts"
"github.com/apisix/manager-api/log"
)

var resources = map[string]string{
Expand Down
2 changes: 1 addition & 1 deletion api/internal/handler/authentication/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/shiningrush/droplet/wrapper"
wgin "github.com/shiningrush/droplet/wrapper/gin"

"github.com/apisix/manager-api/conf"
"github.com/apisix/manager-api/internal/conf"
"github.com/apisix/manager-api/internal/handler"
)

Expand Down
2 changes: 1 addition & 1 deletion api/internal/handler/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/shiningrush/droplet/wrapper"
wgin "github.com/shiningrush/droplet/wrapper/gin"

"github.com/apisix/manager-api/conf"
"github.com/apisix/manager-api/internal/conf"
"github.com/apisix/manager-api/internal/handler"
)

Expand Down
7 changes: 3 additions & 4 deletions api/internal/handler/route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,15 @@ import (
"github.com/shiningrush/droplet"
"github.com/shiningrush/droplet/data"
"github.com/shiningrush/droplet/wrapper"
wgin "github.com/shiningrush/droplet/wrapper/gin"
"github.com/yuin/gopher-lua"

"github.com/apisix/manager-api/conf"
wgin "github.com/shiningrush/droplet/wrapper/gin"
"github.com/apisix/manager-api/internal/conf"
"github.com/apisix/manager-api/internal/core/entity"
"github.com/apisix/manager-api/internal/core/store"
"github.com/apisix/manager-api/internal/handler"
"github.com/apisix/manager-api/internal/log"
"github.com/apisix/manager-api/internal/utils"
"github.com/apisix/manager-api/internal/utils/consts"
"github.com/apisix/manager-api/log"
)

type Handler struct {
Expand Down
2 changes: 1 addition & 1 deletion api/internal/handler/route/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/shiningrush/droplet/data"
"github.com/stretchr/testify/assert"

"github.com/apisix/manager-api/conf"
"github.com/apisix/manager-api/internal/conf"
"github.com/apisix/manager-api/internal/core/entity"
"github.com/apisix/manager-api/internal/core/storage"
"github.com/apisix/manager-api/internal/core/store"
Expand Down
2 changes: 1 addition & 1 deletion api/internal/handler/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/shiningrush/droplet"
"github.com/stretchr/testify/assert"

"github.com/apisix/manager-api/conf"
"github.com/apisix/manager-api/internal/conf"
"github.com/apisix/manager-api/internal/core/entity"
"github.com/apisix/manager-api/internal/core/storage"
"github.com/apisix/manager-api/internal/core/store"
Expand Down
2 changes: 1 addition & 1 deletion api/internal/handler/ssl/ssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"github.com/shiningrush/droplet/wrapper"
wgin "github.com/shiningrush/droplet/wrapper/gin"

"github.com/apisix/manager-api/conf"
"github.com/apisix/manager-api/internal/conf"
"github.com/apisix/manager-api/internal/core/entity"
"github.com/apisix/manager-api/internal/core/store"
"github.com/apisix/manager-api/internal/handler"
Expand Down
2 changes: 1 addition & 1 deletion api/internal/handler/ssl/ssl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/shiningrush/droplet"
"github.com/stretchr/testify/assert"

"github.com/apisix/manager-api/conf"
"github.com/apisix/manager-api/internal/conf"
"github.com/apisix/manager-api/internal/core/entity"
"github.com/apisix/manager-api/internal/core/storage"
"github.com/apisix/manager-api/internal/core/store"
Expand Down
2 changes: 1 addition & 1 deletion api/internal/handler/upstream/upstream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/shiningrush/droplet"
"github.com/stretchr/testify/assert"

"github.com/apisix/manager-api/conf"
"github.com/apisix/manager-api/internal/conf"
"github.com/apisix/manager-api/internal/core/entity"
"github.com/apisix/manager-api/internal/core/storage"
"github.com/apisix/manager-api/internal/core/store"
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion api/log/zap.go → api/internal/log/zap.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"go.uber.org/zap"
"go.uber.org/zap/zapcore"

"github.com/apisix/manager-api/conf"
"github.com/apisix/manager-api/internal/conf"
)

var logger *zap.SugaredLogger
Expand Down
6 changes: 3 additions & 3 deletions api/internal/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (
"github.com/gin-contrib/static"
"github.com/gin-gonic/gin"

"github.com/apisix/manager-api/conf"
"github.com/apisix/manager-api/filter"
"github.com/apisix/manager-api/internal/conf"
"github.com/apisix/manager-api/internal/filter"
"github.com/apisix/manager-api/internal/handler"
"github.com/apisix/manager-api/internal/handler/authentication"
"github.com/apisix/manager-api/internal/handler/consumer"
Expand All @@ -40,7 +40,7 @@ import (
"github.com/apisix/manager-api/internal/handler/service"
"github.com/apisix/manager-api/internal/handler/ssl"
"github.com/apisix/manager-api/internal/handler/upstream"
"github.com/apisix/manager-api/log"
"github.com/apisix/manager-api/internal/log"
)

func SetUpRouter() *gin.Engine {
Expand Down
2 changes: 1 addition & 1 deletion api/test/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ RUN mkdir -p /go/manager-api/conf \
&& mkdir -p /go/manager-api/build-tools \
&& go env -w GOPROXY=https://goproxy.io,direct \
&& export GOPROXY=https://goproxy.io \
&& go build -o /go/manager-api/manager-api \
&& go build -o /go/manager-api/manager-api ./cmd/manager \
&& mv /go/src/github.com/apisix/manager-api/entry.sh /go/manager-api/ \
&& mv /go/src/github.com/apisix/manager-api/build-tools/* /go/manager-api/build-tools/ \
&& mv /go/src/github.com/apisix/manager-api/conf/conf.yaml /go/manager-api/conf/conf.yaml \
Expand Down
2 changes: 1 addition & 1 deletion api/test/shell/cli_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ clean_logfile() {
trap clean_up EXIT

export GO111MODULE=on
go build -o ./manager-api -ldflags "-X github.com/apisix/manager-api/cmd.Version=${VERSION}" .
go build -o ./manager-api -ldflags "-X github.com/apisix/manager-api/cmd.Version=${VERSION}" ./cmd/manager

# default level: warn, path: logs/error.log

Expand Down

0 comments on commit cc9eb35

Please sign in to comment.