├── docs └── img │ ├── rk-op.gif │ ├── boot-arch.png │ ├── rk-boot-logo.png │ └── wechat-group-cn.png ├── .golangci.yml ├── example ├── web │ ├── gf │ │ ├── docs │ │ │ ├── img │ │ │ │ ├── gf-arch.png │ │ │ │ ├── simple-sw.png │ │ │ │ └── simple-docs.png │ │ │ ├── swagger.yaml │ │ │ └── swagger.json │ │ ├── Makefile │ │ ├── main.go │ │ ├── README.md │ │ └── go.mod │ ├── gin │ │ ├── docs │ │ │ ├── img │ │ │ │ ├── gin-arch.png │ │ │ │ ├── simple-sw.png │ │ │ │ └── simple-docs.png │ │ │ ├── swagger.yaml │ │ │ └── swagger.json │ │ ├── Makefile │ │ ├── main.go │ │ ├── README.md │ │ └── go.mod │ ├── mux │ │ ├── docs │ │ │ ├── img │ │ │ │ ├── mux-arch.png │ │ │ │ ├── simple-sw.png │ │ │ │ └── simple-docs.png │ │ │ ├── swagger.yaml │ │ │ └── swagger.json │ │ ├── Makefile │ │ ├── main.go │ │ ├── go.mod │ │ └── README.md │ ├── echo │ │ ├── docs │ │ │ ├── img │ │ │ │ ├── echo-arch.png │ │ │ │ ├── simple-docs.png │ │ │ │ └── simple-sw.png │ │ │ ├── swagger.yaml │ │ │ └── swagger.json │ │ ├── Makefile │ │ ├── main.go │ │ ├── README.md │ │ └── go.mod │ ├── fiber │ │ ├── docs │ │ │ ├── img │ │ │ │ ├── fiber-arch.png │ │ │ │ ├── simple-sw.png │ │ │ │ └── simple-docs.png │ │ │ ├── swagger.yaml │ │ │ └── swagger.json │ │ ├── Makefile │ │ ├── main.go │ │ ├── README.md │ │ └── go.mod │ ├── grpc │ │ ├── docs │ │ │ └── img │ │ │ │ ├── grpc-arch.png │ │ │ │ ├── simple-docs.png │ │ │ │ └── simple-sw.png │ │ ├── buf.yaml │ │ ├── api │ │ │ ├── v1 │ │ │ │ ├── gw_mapping.yaml │ │ │ │ └── greeter.proto │ │ │ └── gen │ │ │ │ └── v1 │ │ │ │ ├── greeter.swagger.json │ │ │ │ └── greeter_grpc.pb.go │ │ ├── Makefile │ │ ├── third-party │ │ │ ├── googleapis │ │ │ │ ├── README.grpc-gateway │ │ │ │ └── google │ │ │ │ │ ├── api │ │ │ │ │ ├── annotations.proto │ │ │ │ │ └── httpbody.proto │ │ │ │ │ └── rpc │ │ │ │ │ └── status.proto │ │ │ └── protoc-gen-openapiv2 │ │ │ │ └── options │ │ │ │ └── annotations.proto │ │ ├── buf.gen.yaml │ │ ├── main.go │ │ └── go.mod │ └── zero │ │ ├── docs │ │ ├── img │ │ │ ├── simple-docs.png │ │ │ ├── simple-sw.png │ │ │ └── zero-arch.png │ │ ├── swagger.yaml │ │ └── swagger.json │ │ ├── Makefile │ │ ├── main.go │ │ ├── go.mod │ │ └── README.md ├── middleware │ └── jwt │ │ └── gin │ │ ├── img │ │ ├── login.png │ │ ├── success.png │ │ └── authorise.png │ │ ├── boot.yaml │ │ ├── Makefile │ │ ├── docs │ │ ├── swagger.yaml │ │ └── swagger.json │ │ ├── main.go │ │ ├── go.mod │ │ └── README.md ├── cache │ └── redis │ │ ├── boot.yaml │ │ ├── main.go │ │ ├── go.mod │ │ └── README.md └── database │ ├── mongodb-todolist │ ├── Makefile │ ├── boot.yaml │ └── go.mod │ ├── sqlite │ ├── boot.yaml │ ├── main.go │ └── go.mod │ ├── sqlserver │ ├── boot.yaml │ ├── main.go │ └── go.mod │ ├── clickhouse │ ├── boot.yaml │ ├── main.go │ └── go.mod │ ├── postgres │ ├── boot.yaml │ ├── main.go │ └── go.mod │ ├── mysql │ ├── boot.yaml │ ├── main.go │ └── go.mod │ ├── mongodb │ ├── boot.yaml │ ├── main.go │ └── go.mod │ └── redis │ ├── main.go │ ├── boot.yaml │ └── go.mod ├── testdata └── boot.yaml ├── .github ├── ISSUE_TEMPLATE │ ├── custom.md │ ├── feature_request.md │ └── bug_report.md └── workflows │ └── ci.yml ├── .gitignore ├── Makefile ├── go.mod ├── CONTRIBUTING.md └── CODE_OF_CONDUCT.md /docs/img/rk-op.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rookie-ninja/rk-boot/HEAD/docs/img/rk-op.gif -------------------------------------------------------------------------------- /docs/img/boot-arch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rookie-ninja/rk-boot/HEAD/docs/img/boot-arch.png -------------------------------------------------------------------------------- /docs/img/rk-boot-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rookie-ninja/rk-boot/HEAD/docs/img/rk-boot-logo.png -------------------------------------------------------------------------------- /docs/img/wechat-group-cn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rookie-ninja/rk-boot/HEAD/docs/img/wechat-group-cn.png -------------------------------------------------------------------------------- /.golangci.yml: -------------------------------------------------------------------------------- 1 | linters: 2 | disable-all: true 3 | enable: 4 | - structcheck 5 | # - errcheck 6 | # - staticcheck -------------------------------------------------------------------------------- /example/web/gf/docs/img/gf-arch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rookie-ninja/rk-boot/HEAD/example/web/gf/docs/img/gf-arch.png -------------------------------------------------------------------------------- /example/web/gf/docs/img/simple-sw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rookie-ninja/rk-boot/HEAD/example/web/gf/docs/img/simple-sw.png -------------------------------------------------------------------------------- /example/web/gin/docs/img/gin-arch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rookie-ninja/rk-boot/HEAD/example/web/gin/docs/img/gin-arch.png -------------------------------------------------------------------------------- /example/web/gin/docs/img/simple-sw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rookie-ninja/rk-boot/HEAD/example/web/gin/docs/img/simple-sw.png -------------------------------------------------------------------------------- /example/web/mux/docs/img/mux-arch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rookie-ninja/rk-boot/HEAD/example/web/mux/docs/img/mux-arch.png -------------------------------------------------------------------------------- /example/web/mux/docs/img/simple-sw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rookie-ninja/rk-boot/HEAD/example/web/mux/docs/img/simple-sw.png -------------------------------------------------------------------------------- /example/middleware/jwt/gin/img/login.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rookie-ninja/rk-boot/HEAD/example/middleware/jwt/gin/img/login.png -------------------------------------------------------------------------------- /example/web/echo/docs/img/echo-arch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rookie-ninja/rk-boot/HEAD/example/web/echo/docs/img/echo-arch.png -------------------------------------------------------------------------------- /example/web/echo/docs/img/simple-docs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rookie-ninja/rk-boot/HEAD/example/web/echo/docs/img/simple-docs.png -------------------------------------------------------------------------------- /example/web/echo/docs/img/simple-sw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rookie-ninja/rk-boot/HEAD/example/web/echo/docs/img/simple-sw.png -------------------------------------------------------------------------------- /example/web/fiber/docs/img/fiber-arch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rookie-ninja/rk-boot/HEAD/example/web/fiber/docs/img/fiber-arch.png -------------------------------------------------------------------------------- /example/web/fiber/docs/img/simple-sw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rookie-ninja/rk-boot/HEAD/example/web/fiber/docs/img/simple-sw.png -------------------------------------------------------------------------------- /example/web/gf/docs/img/simple-docs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rookie-ninja/rk-boot/HEAD/example/web/gf/docs/img/simple-docs.png -------------------------------------------------------------------------------- /example/web/gin/docs/img/simple-docs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rookie-ninja/rk-boot/HEAD/example/web/gin/docs/img/simple-docs.png -------------------------------------------------------------------------------- /example/web/grpc/docs/img/grpc-arch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rookie-ninja/rk-boot/HEAD/example/web/grpc/docs/img/grpc-arch.png -------------------------------------------------------------------------------- /example/web/grpc/docs/img/simple-docs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rookie-ninja/rk-boot/HEAD/example/web/grpc/docs/img/simple-docs.png -------------------------------------------------------------------------------- /example/web/grpc/docs/img/simple-sw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rookie-ninja/rk-boot/HEAD/example/web/grpc/docs/img/simple-sw.png -------------------------------------------------------------------------------- /example/web/mux/docs/img/simple-docs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rookie-ninja/rk-boot/HEAD/example/web/mux/docs/img/simple-docs.png -------------------------------------------------------------------------------- /example/web/zero/docs/img/simple-docs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rookie-ninja/rk-boot/HEAD/example/web/zero/docs/img/simple-docs.png -------------------------------------------------------------------------------- /example/web/zero/docs/img/simple-sw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rookie-ninja/rk-boot/HEAD/example/web/zero/docs/img/simple-sw.png -------------------------------------------------------------------------------- /example/web/zero/docs/img/zero-arch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rookie-ninja/rk-boot/HEAD/example/web/zero/docs/img/zero-arch.png -------------------------------------------------------------------------------- /example/middleware/jwt/gin/img/success.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rookie-ninja/rk-boot/HEAD/example/middleware/jwt/gin/img/success.png -------------------------------------------------------------------------------- /example/web/fiber/docs/img/simple-docs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rookie-ninja/rk-boot/HEAD/example/web/fiber/docs/img/simple-docs.png -------------------------------------------------------------------------------- /testdata/boot.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | logger: 3 | - name: my-logger 4 | event: 5 | - name: my-event 6 | myEntry: 7 | name: ut 8 | enabled: true -------------------------------------------------------------------------------- /example/middleware/jwt/gin/img/authorise.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rookie-ninja/rk-boot/HEAD/example/middleware/jwt/gin/img/authorise.png -------------------------------------------------------------------------------- /example/web/grpc/buf.yaml: -------------------------------------------------------------------------------- 1 | version: v1beta1 2 | name: github.com/rk-dev/rk-boot 3 | build: 4 | roots: 5 | - api 6 | - third-party/googleapis -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/custom.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Custom issue template 3 | about: Describe this issue template's purpose here. 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | -------------------------------------------------------------------------------- /example/cache/redis/boot.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | gin: 3 | - name: cache-service 4 | port: 8080 5 | enabled: true 6 | cache: 7 | - name: redis-cache 8 | enabled: true 9 | local: 10 | enabled: false 11 | redis: 12 | enabled: true -------------------------------------------------------------------------------- /example/web/grpc/api/v1/gw_mapping.yaml: -------------------------------------------------------------------------------- 1 | type: google.api.Service 2 | config_version: 3 3 | 4 | # Please refer google.api.Http in third-party/googleapis/google/api/http.proto file for details. 5 | http: 6 | rules: 7 | - selector: api.v1.Greeter.Hello 8 | get: /v1/hello 9 | -------------------------------------------------------------------------------- /example/middleware/jwt/gin/boot.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | gin: 3 | - name: greeter 4 | port: 8080 5 | enabled: true 6 | sw: 7 | enabled: true 8 | middleware: 9 | jwt: 10 | enabled: true 11 | ignore: 12 | - "/v1/login" 13 | - "/sw" 14 | -------------------------------------------------------------------------------- /example/web/grpc/api/v1/greeter.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package api.v1; 4 | 5 | option go_package = "api/v1/greeter"; 6 | 7 | service Greeter { 8 | rpc Hello (HelloRequest) returns (HelloResponse) {} 9 | } 10 | 11 | message HelloRequest {} 12 | 13 | message HelloResponse { 14 | string my_message = 1; 15 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, built with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | 14 | .idea 15 | 16 | # Dependency directories (remove the comment below to include it) 17 | # vendor/ 18 | 19 | # ut coverage 20 | coverage.txt 21 | 22 | /example/grpc/logs 23 | /example/gin/logs -------------------------------------------------------------------------------- /example/web/grpc/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all 2 | all: lint fmt buf 3 | 4 | .PHONY: lint 5 | lint: 6 | @echo "[golangci-lint] Running golangci-lint..." 7 | @golangci-lint run 2>&1 8 | @echo "------------------------------------[Done]" 9 | 10 | .PHONY: fmt 11 | fmt: 12 | @echo "[fmt] Format go project..." 13 | @gofmt -s -w . 2>&1 14 | @echo "------------------------------------[Done]" 15 | 16 | .PHONY: buf 17 | buf: 18 | @echo "[buf] Running buf..." 19 | @buf generate --path api/v1 20 | -------------------------------------------------------------------------------- /example/web/grpc/third-party/googleapis/README.grpc-gateway: -------------------------------------------------------------------------------- 1 | Google APIs 2 | ============ 3 | 4 | Project: Google APIs 5 | URL: https://github.com/google/googleapis 6 | Revision: 3544ab16c3342d790b00764251e348705991ea4b 7 | License: Apache License 2.0 8 | 9 | 10 | Imported Files 11 | --------------- 12 | 13 | - google/api/annotations.proto 14 | - google/api/http.proto 15 | - google/api/httpbody.proto 16 | 17 | 18 | Generated Files 19 | ---------------- 20 | 21 | They are generated from the .proto files by protoc-gen-go. 22 | - google/api/annotations.pb.go 23 | - google/api/http.pb.go 24 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all 2 | all: test lint fmt 3 | 4 | .PHONY: lint 5 | lint: 6 | @echo "[golangci-lint] Running golangci-lint..." 7 | @golangci-lint run 2>&1 8 | @echo "------------------------------------[Done]" 9 | 10 | .PHONY: test 11 | test: 12 | @echo "[test] Running go test..." 13 | @go test ./... -coverprofile coverage.txt 2>&1 14 | @go tool cover -html=coverage.txt 15 | @echo "------------------------------------[Done]" 16 | 17 | .PHONY: fmt 18 | fmt: 19 | @echo "[fmt] Format go project..." 20 | @gofmt -s -w . 2>&1 21 | @echo "------------------------------------[Done]" 22 | 23 | -------------------------------------------------------------------------------- /example/web/echo/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all 2 | all: lint fmt swag 3 | 4 | .PHONY: lint 5 | lint: 6 | @echo "[golangci-lint] Running golangci-lint..." 7 | @golangci-lint run 2>&1 8 | @echo "------------------------------------[Done]" 9 | 10 | .PHONY: fmt 11 | fmt: 12 | @echo "[fmt] Format go project..." 13 | @gofmt -s -w . 2>&1 14 | @echo "------------------------------------[Done]" 15 | 16 | .PHONY: swag 17 | swag: 18 | @echo "[swag] Running swag..." 19 | @swag init --generalInfo main.go --propertyStrategy camelcase 20 | @rm -rf docs/docs.go 21 | @echo "------------------------------------[Done]" 22 | 23 | 24 | -------------------------------------------------------------------------------- /example/web/fiber/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all 2 | all: lint fmt swag 3 | 4 | .PHONY: lint 5 | lint: 6 | @echo "[golangci-lint] Running golangci-lint..." 7 | @golangci-lint run 2>&1 8 | @echo "------------------------------------[Done]" 9 | 10 | .PHONY: fmt 11 | fmt: 12 | @echo "[fmt] Format go project..." 13 | @gofmt -s -w . 2>&1 14 | @echo "------------------------------------[Done]" 15 | 16 | .PHONY: swag 17 | swag: 18 | @echo "[swag] Running swag..." 19 | @swag init --generalInfo main.go --propertyStrategy camelcase 20 | @rm -rf docs/docs.go 21 | @echo "------------------------------------[Done]" 22 | 23 | 24 | -------------------------------------------------------------------------------- /example/web/gf/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all 2 | all: lint fmt swag 3 | 4 | .PHONY: lint 5 | lint: 6 | @echo "[golangci-lint] Running golangci-lint..." 7 | @golangci-lint run 2>&1 8 | @echo "------------------------------------[Done]" 9 | 10 | .PHONY: fmt 11 | fmt: 12 | @echo "[fmt] Format go project..." 13 | @gofmt -s -w . 2>&1 14 | @echo "------------------------------------[Done]" 15 | 16 | .PHONY: swag 17 | swag: 18 | @echo "[swag] Running swag..." 19 | @swag init --generalInfo main.go --propertyStrategy camelcase 20 | @rm -rf docs/docs.go 21 | @echo "------------------------------------[Done]" 22 | 23 | 24 | -------------------------------------------------------------------------------- /example/web/gin/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all 2 | all: lint fmt swag 3 | 4 | .PHONY: lint 5 | lint: 6 | @echo "[golangci-lint] Running golangci-lint..." 7 | @golangci-lint run 2>&1 8 | @echo "------------------------------------[Done]" 9 | 10 | .PHONY: fmt 11 | fmt: 12 | @echo "[fmt] Format go project..." 13 | @gofmt -s -w . 2>&1 14 | @echo "------------------------------------[Done]" 15 | 16 | .PHONY: swag 17 | swag: 18 | @echo "[swag] Running swag..." 19 | @swag init --generalInfo main.go --propertyStrategy camelcase 20 | @rm -rf docs/docs.go 21 | @echo "------------------------------------[Done]" 22 | 23 | 24 | -------------------------------------------------------------------------------- /example/web/mux/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all 2 | all: lint fmt swag 3 | 4 | .PHONY: lint 5 | lint: 6 | @echo "[golangci-lint] Running golangci-lint..." 7 | @golangci-lint run 2>&1 8 | @echo "------------------------------------[Done]" 9 | 10 | .PHONY: fmt 11 | fmt: 12 | @echo "[fmt] Format go project..." 13 | @gofmt -s -w . 2>&1 14 | @echo "------------------------------------[Done]" 15 | 16 | .PHONY: swag 17 | swag: 18 | @echo "[swag] Running swag..." 19 | @swag init --generalInfo main.go --propertyStrategy camelcase 20 | @rm -rf docs/docs.go 21 | @echo "------------------------------------[Done]" 22 | 23 | 24 | -------------------------------------------------------------------------------- /example/web/zero/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all 2 | all: lint fmt swag 3 | 4 | .PHONY: lint 5 | lint: 6 | @echo "[golangci-lint] Running golangci-lint..." 7 | @golangci-lint run 2>&1 8 | @echo "------------------------------------[Done]" 9 | 10 | .PHONY: fmt 11 | fmt: 12 | @echo "[fmt] Format go project..." 13 | @gofmt -s -w . 2>&1 14 | @echo "------------------------------------[Done]" 15 | 16 | .PHONY: swag 17 | swag: 18 | @echo "[swag] Running swag..." 19 | @swag init --generalInfo main.go --propertyStrategy camelcase 20 | @rm -rf docs/docs.go 21 | @echo "------------------------------------[Done]" 22 | 23 | 24 | -------------------------------------------------------------------------------- /example/middleware/jwt/gin/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all 2 | all: lint fmt swag 3 | 4 | .PHONY: lint 5 | lint: 6 | @echo "[golangci-lint] Running golangci-lint..." 7 | @golangci-lint run 2>&1 8 | @echo "------------------------------------[Done]" 9 | 10 | .PHONY: fmt 11 | fmt: 12 | @echo "[fmt] Format go project..." 13 | @gofmt -s -w . 2>&1 14 | @echo "------------------------------------[Done]" 15 | 16 | .PHONY: swag 17 | swag: 18 | @echo "[swag] Running swag..." 19 | @swag init --generalInfo main.go --propertyStrategy camelcase 20 | @rm -rf docs/docs.go 21 | @echo "------------------------------------[Done]" 22 | 23 | 24 | -------------------------------------------------------------------------------- /example/web/grpc/buf.gen.yaml: -------------------------------------------------------------------------------- 1 | version: v1beta1 2 | plugins: 3 | - name: go 4 | out: api/gen 5 | opt: 6 | - paths=source_relative 7 | - name: go-grpc 8 | out: api/gen 9 | opt: 10 | - paths=source_relative 11 | - require_unimplemented_servers=false 12 | - name: grpc-gateway 13 | out: api/gen 14 | opt: 15 | - paths=source_relative 16 | - grpc_api_configuration=api/v1/gw_mapping.yaml 17 | - allow_repeated_fields_in_body=true 18 | - generate_unbound_methods=true 19 | - name: openapiv2 20 | out: api/gen 21 | opt: 22 | - grpc_api_configuration=api/v1/gw_mapping.yaml 23 | - allow_repeated_fields_in_body=true 24 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: build 2 | 3 | on: 4 | push: 5 | branches: [ '**' ] 6 | pull_request: 7 | branches: [ '**' ] 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v2 14 | - name: Setup Go 15 | uses: actions/setup-go@v2 16 | with: 17 | go-version: 1.18 18 | - name: Setup golangci-lint 19 | uses: golangci/golangci-lint-action@v2.5.2 20 | - name: Run linter 21 | run: make lint 22 | - name: Run test coverage 23 | run: go test $(go list ./... | grep -v example) -coverprofile=coverage.txt -covermode=atomic 24 | - name: Upload coverage to Codecov 25 | run: bash <(curl -s https://codecov.io/bash) 26 | -------------------------------------------------------------------------------- /example/database/mongodb-todolist/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all 2 | all: lint fmt swag 3 | 4 | .PHONY: lint 5 | lint: 6 | @echo "[golangci-lint] Running golangci-lint..." 7 | @golangci-lint run 2>&1 8 | @echo "------------------------------------[Done]" 9 | 10 | .PHONY: fmt 11 | fmt: 12 | @echo "[fmt] Format go project..." 13 | @gofmt -s -w . 2>&1 14 | @echo "------------------------------------[Done]" 15 | 16 | .PHONY: swag 17 | swag: 18 | @echo "[swag] Running swag..." 19 | @swag init --generalInfo main.go --propertyStrategy camelcase 20 | @rm -rf docs/docs.go 21 | @echo "------------------------------------[Done]" 22 | 23 | .PHONY: zip 24 | zip: 25 | @echo "[zip] Compress to zip file..." 26 | @zip -r rk-demo.zip * 27 | @echo "------------------------------------[Done]" 28 | 29 | -------------------------------------------------------------------------------- /example/web/mux/docs/swagger.yaml: -------------------------------------------------------------------------------- 1 | definitions: 2 | main.GreeterResponse: 3 | properties: 4 | message: 5 | type: string 6 | type: object 7 | info: 8 | contact: {} 9 | description: This is a greeter service with rk-boot. 10 | title: RK Swagger for Mux 11 | version: "1.0" 12 | paths: 13 | /v1/greeter: 14 | get: 15 | operationId: "1" 16 | parameters: 17 | - description: Input name 18 | in: query 19 | name: name 20 | required: true 21 | type: string 22 | produces: 23 | - application/json 24 | responses: 25 | "200": 26 | description: OK 27 | schema: 28 | $ref: '#/definitions/main.GreeterResponse' 29 | summary: Greeter service 30 | swagger: "2.0" 31 | -------------------------------------------------------------------------------- /example/database/sqlite/boot.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | gin: 3 | - name: user-service 4 | port: 8080 5 | enabled: true 6 | sqlite: 7 | - name: user-db # Required 8 | enabled: true # Required 9 | domain: "*" # Optional 10 | database: 11 | - name: user # Required 12 | # inMemory: true # Optional, default: false 13 | # dbDir: "" # Optional, default: "", directory where db file created or imported, can be absolute or relative path 14 | # dryRun: true # Optional, default: false 15 | # params: [] # Optional, default: ["cache=shared"] 16 | # loggerEntry: "" # Optional, default: default logger with STDOUT 17 | -------------------------------------------------------------------------------- /example/database/sqlserver/boot.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | gin: 3 | - name: user-service 4 | port: 8080 5 | enabled: true 6 | sqlServer: 7 | - name: user-db # Required 8 | enabled: true # Required 9 | domain: "*" # Optional 10 | addr: "localhost:1433" # Optional, default: localhost:1433 11 | user: sa # Optional, default: sa 12 | pass: pass # Optional, default: pass 13 | database: 14 | - name: user # Required 15 | autoCreate: true # Optional, default: false 16 | # dryRun: true # Optional, default: false 17 | # params: [] # Optional, default: [] 18 | # loggerEntry: "" # Optional, default: default logger with STDOUT 19 | -------------------------------------------------------------------------------- /example/database/clickhouse/boot.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | gin: 3 | - name: user-service 4 | port: 8080 5 | enabled: true 6 | clickhouse: 7 | - name: user-db # Required 8 | enabled: true # Required 9 | domain: "*" # Optional 10 | addr: "localhost:9000" # Optional, default: localhost:9000 11 | user: default # Optional, default: default 12 | pass: "" # Optional, default: "" 13 | database: 14 | - name: user # Required 15 | autoCreate: true # Optional, default: false 16 | # dryRun: false # Optional, default: false 17 | # params: [] # Optional, default: [] 18 | # loggerEntry: "" # Optional, default: default logger with STDOUT -------------------------------------------------------------------------------- /example/database/postgres/boot.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | gin: 3 | - name: user-service 4 | port: 8080 5 | enabled: true 6 | postgres: 7 | - name: user-db # Required 8 | enabled: true # Required 9 | domain: "*" # Optional 10 | addr: "localhost:5432" # Optional, default: localhost:5432 11 | user: postgres # Optional, default: postgres 12 | pass: pass # Optional, default: pass 13 | database: 14 | - name: user # Required 15 | autoCreate: true # Optional, default: false 16 | # dryRun: true # Optional, default: false 17 | # preferSimpleProtocol: false # Optional, default: false 18 | # params: [] # Optional, default: ["sslmode=disable","TimeZone=Asia/Shanghai"] 19 | # loggerEntry: "" # Optional, default: default logger with STDOUT 20 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /example/web/echo/docs/swagger.yaml: -------------------------------------------------------------------------------- 1 | definitions: 2 | main.GreeterResponse: 3 | properties: 4 | message: 5 | type: string 6 | type: object 7 | info: 8 | contact: 9 | email: support@swagger.io 10 | name: API Support 11 | url: http://www.swagger.io/support 12 | description: This is a sample rk-demo server. 13 | license: 14 | name: Apache 2.0 15 | url: http://www.apache.org/licenses/LICENSE-2.0.html 16 | termsOfService: http://swagger.io/terms/ 17 | title: Swagger Example API 18 | version: "1.0" 19 | paths: 20 | /v1/greeter: 21 | get: 22 | operationId: "1" 23 | parameters: 24 | - description: Input name 25 | in: query 26 | name: name 27 | required: true 28 | type: string 29 | produces: 30 | - application/json 31 | responses: 32 | "200": 33 | description: OK 34 | schema: 35 | $ref: '#/definitions/main.GreeterResponse' 36 | summary: Greeter service 37 | securityDefinitions: 38 | BasicAuth: 39 | type: basic 40 | swagger: "2.0" 41 | -------------------------------------------------------------------------------- /example/web/gf/docs/swagger.yaml: -------------------------------------------------------------------------------- 1 | definitions: 2 | main.GreeterResponse: 3 | properties: 4 | message: 5 | type: string 6 | type: object 7 | info: 8 | contact: 9 | email: support@swagger.io 10 | name: API Support 11 | url: http://www.swagger.io/support 12 | description: This is a sample rk-demo server. 13 | license: 14 | name: Apache 2.0 15 | url: http://www.apache.org/licenses/LICENSE-2.0.html 16 | termsOfService: http://swagger.io/terms/ 17 | title: Swagger Example API 18 | version: "1.0" 19 | paths: 20 | /v1/greeter: 21 | get: 22 | operationId: "1" 23 | parameters: 24 | - description: Input name 25 | in: query 26 | name: name 27 | required: true 28 | type: string 29 | produces: 30 | - application/json 31 | responses: 32 | "200": 33 | description: OK 34 | schema: 35 | $ref: '#/definitions/main.GreeterResponse' 36 | summary: Greeter service 37 | securityDefinitions: 38 | BasicAuth: 39 | type: basic 40 | swagger: "2.0" 41 | -------------------------------------------------------------------------------- /example/web/fiber/docs/swagger.yaml: -------------------------------------------------------------------------------- 1 | definitions: 2 | main.GreeterResponse: 3 | properties: 4 | message: 5 | type: string 6 | type: object 7 | info: 8 | contact: 9 | email: support@swagger.io 10 | name: API Support 11 | url: http://www.swagger.io/support 12 | description: This is a sample rk-demo server. 13 | license: 14 | name: Apache 2.0 15 | url: http://www.apache.org/licenses/LICENSE-2.0.html 16 | termsOfService: http://swagger.io/terms/ 17 | title: Swagger Example API 18 | version: "1.0" 19 | paths: 20 | /v1/greeter: 21 | get: 22 | operationId: "1" 23 | parameters: 24 | - description: name 25 | in: query 26 | name: name 27 | required: true 28 | type: string 29 | produces: 30 | - application/json 31 | responses: 32 | "200": 33 | description: OK 34 | schema: 35 | $ref: '#/definitions/main.GreeterResponse' 36 | summary: Greeter 37 | tags: 38 | - Hello 39 | securityDefinitions: 40 | BasicAuth: 41 | type: basic 42 | swagger: "2.0" 43 | -------------------------------------------------------------------------------- /example/web/gin/docs/swagger.yaml: -------------------------------------------------------------------------------- 1 | definitions: 2 | main.GreeterResponse: 3 | properties: 4 | message: 5 | type: string 6 | type: object 7 | info: 8 | contact: 9 | email: support@swagger.io 10 | name: API Support 11 | url: http://www.swagger.io/support 12 | description: This is a sample rk-demo server. 13 | license: 14 | name: Apache 2.0 15 | url: http://www.apache.org/licenses/LICENSE-2.0.html 16 | termsOfService: http://swagger.io/terms/ 17 | title: Swagger Example API 18 | version: "1.0" 19 | paths: 20 | /v1/greeter: 21 | get: 22 | operationId: "1" 23 | parameters: 24 | - description: name 25 | in: query 26 | name: name 27 | required: true 28 | type: string 29 | produces: 30 | - application/json 31 | responses: 32 | "200": 33 | description: OK 34 | schema: 35 | $ref: '#/definitions/main.GreeterResponse' 36 | summary: Greeter 37 | tags: 38 | - Hello 39 | securityDefinitions: 40 | BasicAuth: 41 | type: basic 42 | swagger: "2.0" 43 | -------------------------------------------------------------------------------- /example/web/zero/docs/swagger.yaml: -------------------------------------------------------------------------------- 1 | definitions: 2 | main.GreeterResponse: 3 | properties: 4 | message: 5 | type: string 6 | type: object 7 | info: 8 | contact: 9 | email: support@swagger.io 10 | name: API Support 11 | url: http://www.swagger.io/support 12 | description: This is a sample rk-demo server. 13 | license: 14 | name: Apache 2.0 15 | url: http://www.apache.org/licenses/LICENSE-2.0.html 16 | termsOfService: http://swagger.io/terms/ 17 | title: Swagger Example API 18 | version: "1.0" 19 | paths: 20 | /v1/greeter: 21 | get: 22 | operationId: "1" 23 | parameters: 24 | - description: name 25 | in: query 26 | name: name 27 | required: true 28 | type: string 29 | produces: 30 | - application/json 31 | responses: 32 | "200": 33 | description: OK 34 | schema: 35 | $ref: '#/definitions/main.GreeterResponse' 36 | summary: Greeter 37 | tags: 38 | - Hello 39 | securityDefinitions: 40 | BasicAuth: 41 | type: basic 42 | swagger: "2.0" 43 | -------------------------------------------------------------------------------- /example/middleware/jwt/gin/docs/swagger.yaml: -------------------------------------------------------------------------------- 1 | info: 2 | contact: 3 | email: support@swagger.io 4 | name: API Support 5 | url: http://www.swagger.io/support 6 | description: This is a sample rk-boot server. 7 | license: 8 | name: Apache 2.0 9 | url: http://www.apache.org/licenses/LICENSE-2.0.html 10 | termsOfService: http://swagger.io/terms/ 11 | title: Swagger Example API 12 | version: "1.0" 13 | paths: 14 | /v1/login: 15 | get: 16 | operationId: "1" 17 | parameters: 18 | - description: name 19 | in: query 20 | name: name 21 | required: true 22 | type: string 23 | produces: 24 | - application/json 25 | responses: {} 26 | security: 27 | - JWT: [] 28 | summary: Login 29 | tags: 30 | - JWT 31 | /v1/whoami: 32 | get: 33 | operationId: "2" 34 | produces: 35 | - application/json 36 | responses: {} 37 | security: 38 | - JWT: [] 39 | summary: WhoAmI 40 | tags: 41 | - JWT 42 | securityDefinitions: 43 | JWT: 44 | in: header 45 | name: Authorization 46 | type: apiKey 47 | swagger: "2.0" 48 | -------------------------------------------------------------------------------- /example/web/grpc/third-party/googleapis/google/api/annotations.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package google.api; 18 | 19 | import "google/api/http.proto"; 20 | import "google/protobuf/descriptor.proto"; 21 | 22 | option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; 23 | option java_multiple_files = true; 24 | option java_outer_classname = "AnnotationsProto"; 25 | option java_package = "com.google.api"; 26 | option objc_class_prefix = "GAPI"; 27 | 28 | extend google.protobuf.MethodOptions { 29 | // See `HttpRule`. 30 | HttpRule http = 72295728; 31 | } 32 | -------------------------------------------------------------------------------- /example/database/mysql/boot.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | gin: 3 | - name: user-service 4 | port: 8080 5 | enabled: true 6 | middleware: 7 | logging: 8 | enabled: true 9 | meta: 10 | enabled: true 11 | trace: 12 | enabled: true 13 | mysql: 14 | - name: user-db # Required 15 | enabled: true # Required 16 | domain: "*" # Optional 17 | addr: "localhost:3306" # Optional, default: localhost:3306 18 | user: root # Optional, default: root 19 | pass: pass # Optional, default: pass 20 | protocol: tcp # Optional, default: tcp 21 | database: 22 | - name: demo # Required 23 | autoCreate: true # Optional, default: false 24 | # dryRun: true # Optional, default: false 25 | # params: [] # Optional, default: ["charset=utf8mb4","parseTime=True","loc=Local"] 26 | logger: 27 | level: info 28 | # entry: "" 29 | # encoding: json 30 | # outputPaths: [ "stdout", "log/db.log" ] 31 | # slowThresholdMs: 5000 32 | # ignoreRecordNotFoundError: false -------------------------------------------------------------------------------- /example/web/grpc/main.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 rookie-ninja 2 | // 3 | // Use of this source code is governed by an Apache-style 4 | // license that can be found in the LICENSE file. 5 | 6 | package main 7 | 8 | import ( 9 | "context" 10 | "github.com/rookie-ninja/rk-boot/v2" 11 | "github.com/rookie-ninja/rk-demo/api/gen/v1" 12 | "github.com/rookie-ninja/rk-grpc/v2/boot" 13 | "google.golang.org/grpc" 14 | ) 15 | 16 | func main() { 17 | boot := rkboot.NewBoot() 18 | 19 | // register grpc 20 | entry := rkgrpc.GetGrpcEntry("greeter") 21 | entry.AddRegFuncGrpc(registerGreeter) 22 | entry.AddRegFuncGw(greeter.RegisterGreeterHandlerFromEndpoint) 23 | 24 | // Bootstrap 25 | boot.Bootstrap(context.TODO()) 26 | 27 | // Wait for shutdown sig 28 | boot.WaitForShutdownSig(context.TODO()) 29 | } 30 | 31 | func registerGreeter(server *grpc.Server) { 32 | greeter.RegisterGreeterServer(server, &GreeterServer{}) 33 | } 34 | 35 | //GreeterServer GreeterServer struct 36 | type GreeterServer struct{} 37 | 38 | // Hello response with hello message 39 | func (server *GreeterServer) Hello(_ context.Context, _ *greeter.HelloRequest) (*greeter.HelloResponse, error) { 40 | return &greeter.HelloResponse{ 41 | Message: "hello!", 42 | }, nil 43 | } 44 | -------------------------------------------------------------------------------- /example/cache/redis/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "github.com/gin-gonic/gin" 6 | "github.com/rookie-ninja/rk-boot/v2" 7 | "github.com/rookie-ninja/rk-cache/redis" 8 | "github.com/rookie-ninja/rk-gin/v2/boot" 9 | "net/http" 10 | ) 11 | 12 | var cacheEntry *rkcache.CacheEntry 13 | 14 | func main() { 15 | boot := rkboot.NewBoot() 16 | 17 | boot.Bootstrap(context.TODO()) 18 | 19 | // assign cache 20 | cacheEntry = rkcache.GetCacheEntry("redis-cache") 21 | 22 | // assign router 23 | ginEntry := rkgin.GetGinEntry("cache-service") 24 | ginEntry.Router.GET("/v1/get", Get) 25 | ginEntry.Router.GET("/v1/set", Set) 26 | 27 | boot.WaitForShutdownSig(context.TODO()) 28 | } 29 | 30 | func Get(ctx *gin.Context) { 31 | val := "" 32 | resp := cacheEntry.GetFromCache(&rkcache.CacheReq{ 33 | Key: "demo-key", 34 | Value: &val, 35 | }) 36 | 37 | if resp.Error != nil || !resp.Success { 38 | ctx.JSON(http.StatusInternalServerError, resp.Error) 39 | return 40 | } 41 | 42 | ctx.JSON(http.StatusOK, map[string]string{ 43 | "value": val, 44 | }) 45 | } 46 | 47 | func Set(ctx *gin.Context) { 48 | val, ok := ctx.GetQuery("value") 49 | if !ok { 50 | ctx.JSON(http.StatusBadRequest, "No value found") 51 | } 52 | 53 | cacheEntry.AddToCache(&rkcache.CacheReq{ 54 | Key: "demo-key", 55 | Value: val, 56 | }) 57 | 58 | ctx.JSON(http.StatusOK, map[string]string{ 59 | "value": val, 60 | }) 61 | } 62 | -------------------------------------------------------------------------------- /example/web/mux/main.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 rookie-ninja 2 | // 3 | // Use of this source code is governed by an Apache-style 4 | // license that can be found in the LICENSE file. 5 | package main 6 | 7 | import ( 8 | "context" 9 | _ "embed" 10 | "fmt" 11 | "github.com/rookie-ninja/rk-boot/v2" 12 | "github.com/rookie-ninja/rk-mux/boot" 13 | "github.com/rookie-ninja/rk-mux/middleware" 14 | "net/http" 15 | ) 16 | 17 | // @title RK Swagger for Mux 18 | // @version 1.0 19 | // @description This is a greeter service with rk-boot. 20 | func main() { 21 | // Create a new boot instance. 22 | boot := rkboot.NewBoot() 23 | 24 | // Get MuxEntry 25 | muxEntry := rkmux.GetMuxEntry("greeter") 26 | // Use *mux.Router adding handler. 27 | muxEntry.Router.NewRoute().Path("/v1/greeter").HandlerFunc(Greeter) 28 | 29 | // Bootstrap 30 | boot.Bootstrap(context.TODO()) 31 | 32 | boot.WaitForShutdownSig(context.TODO()) 33 | } 34 | 35 | // Greeter handler 36 | // @Summary Greeter service 37 | // @Id 1 38 | // @version 1.0 39 | // @produce application/json 40 | // @Param name query string true "Input name" 41 | // @Success 200 {object} GreeterResponse 42 | // @Router /v1/greeter [get] 43 | func Greeter(writer http.ResponseWriter, req *http.Request) { 44 | rkmuxmid.WriteJson(writer, http.StatusOK, &GreeterResponse{ 45 | Message: fmt.Sprintf("Hello %s!", req.URL.Query().Get("name")), 46 | }) 47 | } 48 | 49 | type GreeterResponse struct { 50 | Message string 51 | } 52 | -------------------------------------------------------------------------------- /example/web/mux/docs/swagger.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "description": "This is a greeter service with rk-boot.", 5 | "title": "RK Swagger for Mux", 6 | "contact": {}, 7 | "version": "1.0" 8 | }, 9 | "paths": { 10 | "/v1/greeter": { 11 | "get": { 12 | "produces": [ 13 | "application/json" 14 | ], 15 | "summary": "Greeter service", 16 | "operationId": "1", 17 | "parameters": [ 18 | { 19 | "type": "string", 20 | "description": "Input name", 21 | "name": "name", 22 | "in": "query", 23 | "required": true 24 | } 25 | ], 26 | "responses": { 27 | "200": { 28 | "description": "OK", 29 | "schema": { 30 | "$ref": "#/definitions/main.GreeterResponse" 31 | } 32 | } 33 | } 34 | } 35 | } 36 | }, 37 | "definitions": { 38 | "main.GreeterResponse": { 39 | "type": "object", 40 | "properties": { 41 | "message": { 42 | "type": "string" 43 | } 44 | } 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /example/database/mongodb/boot.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | gin: 3 | - name: user-service 4 | port: 8080 5 | enabled: true 6 | mongo: 7 | - name: "my-mongo" # Required 8 | enabled: true # Required 9 | simpleURI: "mongodb://localhost:27017" # Required 10 | database: 11 | - name: "users" # Required 12 | # description: "description" 13 | # locale: "*::*::*::*" 14 | # certEntry: "" 15 | # loggerEntry: "" 16 | # # Belongs to mongoDB client options 17 | # # Please refer to https://github.com/mongodb/mongo-go-driver/blob/master/mongo/options/clientoptions.go 18 | # appName: "" 19 | # auth: 20 | # mechanism: "" 21 | # mechanismProperties: 22 | # a: b 23 | # source: "" 24 | # username: "" 25 | # password: "" 26 | # passwordSet: false 27 | # connectTimeoutMs: 500 28 | # compressors: [] 29 | # direct: false 30 | # disableOCSPEndpointCheck: false 31 | # heartbeatIntervalMs: 10 32 | # hosts: [] 33 | # loadBalanced: false 34 | # localThresholdMs: 1 35 | # maxConnIdleTimeMs: 1 36 | # maxPoolSize: 1 37 | # minPoolSize: 1 38 | # maxConnecting: 1 39 | # replicaSet: "" 40 | # retryReads: false 41 | # retryWrites: false 42 | # serverAPIOptions: 43 | # serverAPIVersion: "" 44 | # strict: false 45 | # deprecationErrors: false 46 | # serverSelectionTimeoutMs: 1 47 | # socketTimeout: 1 48 | # srvMaxHots: 1 49 | # srvServiceName: "" 50 | # zlibLevel: 1 51 | # zstdLevel: 1 52 | # authenticateToAnything: false 53 | 54 | 55 | -------------------------------------------------------------------------------- /example/web/gin/main.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 rookie-ninja 2 | // 3 | // Use of this source code is governed by an Apache-style 4 | // license that can be found in the LICENSE file. 5 | 6 | package main 7 | 8 | import ( 9 | "context" 10 | "fmt" 11 | "github.com/gin-gonic/gin" 12 | "github.com/rookie-ninja/rk-boot/v2" 13 | "github.com/rookie-ninja/rk-gin/v2/boot" 14 | "net/http" 15 | ) 16 | 17 | // @title Swagger Example API 18 | // @version 1.0 19 | // @description This is a sample rk-demo server. 20 | // @termsOfService http://swagger.io/terms/ 21 | 22 | // @securityDefinitions.basic BasicAuth 23 | 24 | // @contact.name API Support 25 | // @contact.url http://www.swagger.io/support 26 | // @contact.email support@swagger.io 27 | 28 | // @license.name Apache 2.0 29 | // @license.url http://www.apache.org/licenses/LICENSE-2.0.html 30 | func main() { 31 | // Create a new boot instance. 32 | boot := rkboot.NewBoot() 33 | 34 | // Register handler 35 | entry := rkgin.GetGinEntry("greeter") 36 | entry.Router.GET("/v1/greeter", Greeter) 37 | 38 | // Bootstrap 39 | boot.Bootstrap(context.TODO()) 40 | 41 | boot.WaitForShutdownSig(context.TODO()) 42 | } 43 | 44 | // Greeter handler 45 | // @Summary Greeter 46 | // @Id 1 47 | // @Tags Hello 48 | // @version 1.0 49 | // @Param name query string true "name" 50 | // @produce application/json 51 | // @Success 200 {object} GreeterResponse 52 | // @Router /v1/greeter [get] 53 | func Greeter(ctx *gin.Context) { 54 | ctx.JSON(http.StatusOK, &GreeterResponse{ 55 | Message: fmt.Sprintf("Hello %s!", ctx.Query("name")), 56 | }) 57 | } 58 | 59 | type GreeterResponse struct { 60 | Message string 61 | } 62 | -------------------------------------------------------------------------------- /example/web/echo/main.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 rookie-ninja 2 | // 3 | // Use of this source code is governed by an Apache-style 4 | // license that can be found in the LICENSE file. 5 | package main 6 | 7 | import ( 8 | "context" 9 | _ "embed" 10 | "fmt" 11 | "github.com/labstack/echo/v4" 12 | "github.com/rookie-ninja/rk-boot/v2" 13 | "github.com/rookie-ninja/rk-echo/boot" 14 | "net/http" 15 | ) 16 | 17 | // @title Swagger Example API 18 | // @version 1.0 19 | // @description This is a sample rk-demo server. 20 | // @termsOfService http://swagger.io/terms/ 21 | 22 | // @securityDefinitions.basic BasicAuth 23 | 24 | // @contact.name API Support 25 | // @contact.url http://www.swagger.io/support 26 | // @contact.email support@swagger.io 27 | 28 | // @license.name Apache 2.0 29 | // @license.url http://www.apache.org/licenses/LICENSE-2.0.html 30 | 31 | func main() { 32 | // Create a new boot instance. 33 | boot := rkboot.NewBoot() 34 | 35 | // Register handler 36 | echoEntry := rkecho.GetEchoEntry("greeter") 37 | echoEntry.Echo.GET("/v1/greeter", Greeter) 38 | 39 | // Bootstrap 40 | boot.Bootstrap(context.TODO()) 41 | 42 | boot.WaitForShutdownSig(context.TODO()) 43 | } 44 | 45 | // Greeter handler 46 | // @Summary Greeter service 47 | // @Id 1 48 | // @version 1.0 49 | // @produce application/json 50 | // @Param name query string true "Input name" 51 | // @Success 200 {object} GreeterResponse 52 | // @Router /v1/greeter [get] 53 | func Greeter(ctx echo.Context) error { 54 | return ctx.JSON(http.StatusOK, &GreeterResponse{ 55 | Message: fmt.Sprintf("Hello %s!", ctx.QueryParam("name")), 56 | }) 57 | } 58 | 59 | type GreeterResponse struct { 60 | Message string 61 | } 62 | -------------------------------------------------------------------------------- /example/web/gf/main.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 rookie-ninja 2 | // 3 | // Use of this source code is governed by an Apache-style 4 | // license that can be found in the LICENSE file. 5 | 6 | package main 7 | 8 | import ( 9 | "context" 10 | "fmt" 11 | "github.com/gogf/gf/v2/net/ghttp" 12 | "github.com/rookie-ninja/rk-boot/v2" 13 | "github.com/rookie-ninja/rk-gf/boot" 14 | "net/http" 15 | ) 16 | 17 | // @title Swagger Example API 18 | // @version 1.0 19 | // @description This is a sample rk-demo server. 20 | // @termsOfService http://swagger.io/terms/ 21 | 22 | // @securityDefinitions.basic BasicAuth 23 | 24 | // @contact.name API Support 25 | // @contact.url http://www.swagger.io/support 26 | // @contact.email support@swagger.io 27 | 28 | // @license.name Apache 2.0 29 | // @license.url http://www.apache.org/licenses/LICENSE-2.0.html 30 | func main() { 31 | // Create a new boot instance. 32 | boot := rkboot.NewBoot() 33 | 34 | // Register handler 35 | entry := rkgf.GetGfEntry("greeter") 36 | entry.Server.BindHandler("/v1/greeter", Greeter) 37 | 38 | // Bootstrap 39 | boot.Bootstrap(context.TODO()) 40 | 41 | boot.WaitForShutdownSig(context.TODO()) 42 | } 43 | 44 | // Greeter handler 45 | // @Summary Greeter service 46 | // @Id 1 47 | // @version 1.0 48 | // @produce application/json 49 | // @Param name query string true "Input name" 50 | // @Success 200 {object} GreeterResponse 51 | // @Router /v1/greeter [get] 52 | func Greeter(ctx *ghttp.Request) { 53 | ctx.Response.WriteHeader(http.StatusOK) 54 | ctx.Response.WriteJson(&GreeterResponse{ 55 | Message: fmt.Sprintf("Hello %s!", ctx.GetQuery("name").String()), 56 | }) 57 | } 58 | 59 | type GreeterResponse struct { 60 | Message string 61 | } 62 | -------------------------------------------------------------------------------- /example/web/zero/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "encoding/json" 6 | "fmt" 7 | "github.com/rookie-ninja/rk-boot/v2" 8 | "github.com/rookie-ninja/rk-zero/boot" 9 | "github.com/zeromicro/go-zero/rest" 10 | "net/http" 11 | ) 12 | 13 | // @title Swagger Example API 14 | // @version 1.0 15 | // @description This is a sample rk-demo server. 16 | // @termsOfService http://swagger.io/terms/ 17 | 18 | // @securityDefinitions.basic BasicAuth 19 | 20 | // @contact.name API Support 21 | // @contact.url http://www.swagger.io/support 22 | // @contact.email support@swagger.io 23 | 24 | // @license.name Apache 2.0 25 | // @license.url http://www.apache.org/licenses/LICENSE-2.0.html 26 | 27 | func main() { 28 | // Create a new boot instance. 29 | boot := rkboot.NewBoot() 30 | 31 | // Register handler 32 | zeroEntry := rkzero.GetZeroEntry("greeter") 33 | zeroEntry.Server.AddRoute(rest.Route{ 34 | Method: http.MethodGet, 35 | Path: "/v1/greeter", 36 | Handler: Greeter, 37 | }) 38 | 39 | // Bootstrap 40 | boot.Bootstrap(context.TODO()) 41 | 42 | boot.WaitForShutdownSig(context.TODO()) 43 | } 44 | 45 | // Greeter handler 46 | // @Summary Greeter 47 | // @Id 1 48 | // @Tags Hello 49 | // @version 1.0 50 | // @Param name query string true "name" 51 | // @produce application/json 52 | // @Success 200 {object} GreeterResponse 53 | // @Router /v1/greeter [get] 54 | func Greeter(writer http.ResponseWriter, request *http.Request) { 55 | writer.WriteHeader(http.StatusOK) 56 | resp := &GreeterResponse{ 57 | Message: fmt.Sprintf("Hello %s!", request.URL.Query().Get("name")), 58 | } 59 | bytes, _ := json.Marshal(resp) 60 | writer.Write(bytes) 61 | } 62 | 63 | type GreeterResponse struct { 64 | Message string 65 | } 66 | -------------------------------------------------------------------------------- /example/web/fiber/main.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 rookie-ninja 2 | // 3 | // Use of this source code is governed by an Apache-style 4 | // license that can be found in the LICENSE file. 5 | 6 | package main 7 | 8 | import ( 9 | "context" 10 | "fmt" 11 | "github.com/gofiber/fiber/v2" 12 | "github.com/rookie-ninja/rk-boot/v2" 13 | "github.com/rookie-ninja/rk-fiber/boot" 14 | "net/http" 15 | ) 16 | 17 | // @title Swagger Example API 18 | // @version 1.0 19 | // @description This is a sample rk-demo server. 20 | // @termsOfService http://swagger.io/terms/ 21 | 22 | // @securityDefinitions.basic BasicAuth 23 | 24 | // @contact.name API Support 25 | // @contact.url http://www.swagger.io/support 26 | // @contact.email support@swagger.io 27 | 28 | // @license.name Apache 2.0 29 | // @license.url http://www.apache.org/licenses/LICENSE-2.0.html 30 | func main() { 31 | // Create a new boot instance. 32 | boot := rkboot.NewBoot() 33 | 34 | // Bootstrap 35 | boot.Bootstrap(context.TODO()) 36 | 37 | // Register handler 38 | entry := rkfiber.GetFiberEntry("greeter") 39 | entry.App.Get("/v1/greeter", Greeter) 40 | // This is required!!! 41 | entry.RefreshFiberRoutes() 42 | 43 | boot.WaitForShutdownSig(context.TODO()) 44 | } 45 | 46 | // Greeter handler 47 | // @Summary Greeter 48 | // @Id 1 49 | // @Tags Hello 50 | // @version 1.0 51 | // @Param name query string true "name" 52 | // @produce application/json 53 | // @Success 200 {object} GreeterResponse 54 | // @Router /v1/greeter [get] 55 | func Greeter(ctx *fiber.Ctx) error { 56 | ctx.Response().SetStatusCode(http.StatusOK) 57 | return ctx.JSON(&GreeterResponse{ 58 | Message: fmt.Sprintf("Hello %s!", ctx.Query("name")), 59 | }) 60 | } 61 | 62 | type GreeterResponse struct { 63 | Message string 64 | } 65 | -------------------------------------------------------------------------------- /example/database/mongodb-todolist/boot.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | gin: 3 | - name: todo-service 4 | port: 3000 5 | enabled: true 6 | commonService: 7 | enabled: true 8 | sw: 9 | enabled: true 10 | docs: 11 | enabled: true 12 | prom: 13 | enabled: true 14 | middleware: 15 | logging: 16 | enabled: true 17 | prom: 18 | enabled: true 19 | mongo: 20 | - name: "todo-mongo" # Required 21 | enabled: true # Required 22 | simpleURI: "mongodb://localhost:27017" # Required 23 | database: 24 | - name: "tododb" # Required 25 | # description: "description" 26 | # locale: "*::*::*::*" 27 | # certEntry: "" 28 | # loggerEntry: "" 29 | # # Belongs to mongoDB client options 30 | # # Please refer to https://github.com/mongodb/mongo-go-driver/blob/master/mongo/options/clientoptions.go 31 | # appName: "" 32 | # auth: 33 | # mechanism: "" 34 | # mechanismProperties: 35 | # a: b 36 | # source: "" 37 | # username: "" 38 | # password: "" 39 | # passwordSet: false 40 | # connectTimeoutMs: 500 41 | # compressors: [] 42 | # direct: false 43 | # disableOCSPEndpointCheck: false 44 | # heartbeatIntervalMs: 10 45 | # hosts: [] 46 | # loadBalanced: false 47 | # localThresholdMs: 1 48 | # maxConnIdleTimeMs: 1 49 | # maxPoolSize: 1 50 | # minPoolSize: 1 51 | # maxConnecting: 1 52 | # replicaSet: "" 53 | # retryReads: false 54 | # retryWrites: false 55 | # serverAPIOptions: 56 | # serverAPIVersion: "" 57 | # strict: false 58 | # deprecationErrors: false 59 | # serverSelectionTimeoutMs: 1 60 | # socketTimeout: 1 61 | # srvMaxHots: 1 62 | # srvServiceName: "" 63 | # zlibLevel: 1 64 | # zstdLevel: 1 65 | # authenticateToAnything: false -------------------------------------------------------------------------------- /example/database/redis/main.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 rookie-ninja 2 | // 3 | // Use of this source code is governed by an Apache-style 4 | // license that can be found in the LICENSE file. 5 | package main 6 | 7 | import ( 8 | "context" 9 | "github.com/gin-gonic/gin" 10 | "github.com/go-redis/redis/v8" 11 | "github.com/rookie-ninja/rk-boot/v2" 12 | "github.com/rookie-ninja/rk-db/redis" 13 | "github.com/rookie-ninja/rk-gin/v2/boot" 14 | "net/http" 15 | "time" 16 | ) 17 | 18 | var redisClient *redis.Client 19 | 20 | func main() { 21 | boot := rkboot.NewBoot() 22 | 23 | boot.Bootstrap(context.TODO()) 24 | 25 | // Auto migrate database and init global userDb variable 26 | redisEntry := rkredis.GetRedisEntry("redis") 27 | redisClient, _ = redisEntry.GetClient() 28 | 29 | // Register APIs 30 | ginEntry := rkgin.GetGinEntry("server") 31 | ginEntry.Router.GET("/v1/get", Get) 32 | ginEntry.Router.POST("/v1/set", Set) 33 | 34 | boot.WaitForShutdownSig(context.TODO()) 35 | } 36 | 37 | type KV struct { 38 | Key string `json:"key"` 39 | Value string `json:"value"` 40 | } 41 | 42 | func Set(ctx *gin.Context) { 43 | payload := &KV{} 44 | 45 | if err := ctx.BindJSON(payload); err != nil { 46 | ctx.JSON(http.StatusInternalServerError, err) 47 | return 48 | } 49 | 50 | cmd := redisClient.Set(ctx.Request.Context(), payload.Key, payload.Value, time.Minute) 51 | 52 | if cmd.Err() != nil { 53 | ctx.JSON(http.StatusInternalServerError, cmd.Err()) 54 | return 55 | } 56 | 57 | ctx.Status(http.StatusOK) 58 | } 59 | 60 | func Get(ctx *gin.Context) { 61 | key := ctx.Query("key") 62 | 63 | cmd := redisClient.Get(ctx.Request.Context(), key) 64 | 65 | if cmd.Err() != nil { 66 | ctx.JSON(http.StatusInternalServerError, cmd.Err()) 67 | return 68 | } 69 | 70 | payload := &KV{ 71 | Key: key, 72 | Value: cmd.Val(), 73 | } 74 | 75 | ctx.JSON(http.StatusOK, payload) 76 | } 77 | -------------------------------------------------------------------------------- /example/web/grpc/api/gen/v1/greeter.swagger.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "title": "v1/greeter.proto", 5 | "version": "version not set" 6 | }, 7 | "tags": [ 8 | { 9 | "name": "Greeter" 10 | } 11 | ], 12 | "consumes": [ 13 | "application/json" 14 | ], 15 | "produces": [ 16 | "application/json" 17 | ], 18 | "paths": { 19 | "/v1/hello": { 20 | "get": { 21 | "operationId": "Greeter_Hello", 22 | "responses": { 23 | "200": { 24 | "description": "A successful response.", 25 | "schema": { 26 | "$ref": "#/definitions/v1HelloResponse" 27 | } 28 | }, 29 | "default": { 30 | "description": "An unexpected error response.", 31 | "schema": { 32 | "$ref": "#/definitions/rpcStatus" 33 | } 34 | } 35 | }, 36 | "tags": [ 37 | "Greeter" 38 | ] 39 | } 40 | } 41 | }, 42 | "definitions": { 43 | "protobufAny": { 44 | "type": "object", 45 | "properties": { 46 | "typeUrl": { 47 | "type": "string" 48 | }, 49 | "value": { 50 | "type": "string", 51 | "format": "byte" 52 | } 53 | } 54 | }, 55 | "rpcStatus": { 56 | "type": "object", 57 | "properties": { 58 | "code": { 59 | "type": "integer", 60 | "format": "int32" 61 | }, 62 | "message": { 63 | "type": "string" 64 | }, 65 | "details": { 66 | "type": "array", 67 | "items": { 68 | "$ref": "#/definitions/protobufAny" 69 | } 70 | } 71 | } 72 | }, 73 | "v1HelloResponse": { 74 | "type": "object", 75 | "properties": { 76 | "message": { 77 | "type": "string" 78 | } 79 | } 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /example/web/echo/docs/swagger.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "description": "This is a sample rk-demo server.", 5 | "title": "Swagger Example API", 6 | "termsOfService": "http://swagger.io/terms/", 7 | "contact": { 8 | "name": "API Support", 9 | "url": "http://www.swagger.io/support", 10 | "email": "support@swagger.io" 11 | }, 12 | "license": { 13 | "name": "Apache 2.0", 14 | "url": "http://www.apache.org/licenses/LICENSE-2.0.html" 15 | }, 16 | "version": "1.0" 17 | }, 18 | "paths": { 19 | "/v1/greeter": { 20 | "get": { 21 | "produces": [ 22 | "application/json" 23 | ], 24 | "summary": "Greeter service", 25 | "operationId": "1", 26 | "parameters": [ 27 | { 28 | "type": "string", 29 | "description": "Input name", 30 | "name": "name", 31 | "in": "query", 32 | "required": true 33 | } 34 | ], 35 | "responses": { 36 | "200": { 37 | "description": "OK", 38 | "schema": { 39 | "$ref": "#/definitions/main.GreeterResponse" 40 | } 41 | } 42 | } 43 | } 44 | } 45 | }, 46 | "definitions": { 47 | "main.GreeterResponse": { 48 | "type": "object", 49 | "properties": { 50 | "message": { 51 | "type": "string" 52 | } 53 | } 54 | } 55 | }, 56 | "securityDefinitions": { 57 | "BasicAuth": { 58 | "type": "basic" 59 | } 60 | } 61 | } -------------------------------------------------------------------------------- /example/web/gf/docs/swagger.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "description": "This is a sample rk-demo server.", 5 | "title": "Swagger Example API", 6 | "termsOfService": "http://swagger.io/terms/", 7 | "contact": { 8 | "name": "API Support", 9 | "url": "http://www.swagger.io/support", 10 | "email": "support@swagger.io" 11 | }, 12 | "license": { 13 | "name": "Apache 2.0", 14 | "url": "http://www.apache.org/licenses/LICENSE-2.0.html" 15 | }, 16 | "version": "1.0" 17 | }, 18 | "paths": { 19 | "/v1/greeter": { 20 | "get": { 21 | "produces": [ 22 | "application/json" 23 | ], 24 | "summary": "Greeter service", 25 | "operationId": "1", 26 | "parameters": [ 27 | { 28 | "type": "string", 29 | "description": "Input name", 30 | "name": "name", 31 | "in": "query", 32 | "required": true 33 | } 34 | ], 35 | "responses": { 36 | "200": { 37 | "description": "OK", 38 | "schema": { 39 | "$ref": "#/definitions/main.GreeterResponse" 40 | } 41 | } 42 | } 43 | } 44 | } 45 | }, 46 | "definitions": { 47 | "main.GreeterResponse": { 48 | "type": "object", 49 | "properties": { 50 | "message": { 51 | "type": "string" 52 | } 53 | } 54 | } 55 | }, 56 | "securityDefinitions": { 57 | "BasicAuth": { 58 | "type": "basic" 59 | } 60 | } 61 | } -------------------------------------------------------------------------------- /example/web/grpc/third-party/protoc-gen-openapiv2/options/annotations.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package grpc.gateway.protoc_gen_openapiv2.options; 4 | 5 | import "google/protobuf/descriptor.proto"; 6 | import "protoc-gen-openapiv2/options/openapiv2.proto"; 7 | 8 | option go_package = "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/options"; 9 | 10 | extend google.protobuf.FileOptions { 11 | // ID assigned by protobuf-global-extension-registry@google.com for gRPC-Gateway project. 12 | // 13 | // All IDs are the same, as assigned. It is okay that they are the same, as they extend 14 | // different descriptor messages. 15 | Swagger openapiv2_swagger = 1042; 16 | } 17 | extend google.protobuf.MethodOptions { 18 | // ID assigned by protobuf-global-extension-registry@google.com for gRPC-Gateway project. 19 | // 20 | // All IDs are the same, as assigned. It is okay that they are the same, as they extend 21 | // different descriptor messages. 22 | Operation openapiv2_operation = 1042; 23 | } 24 | extend google.protobuf.MessageOptions { 25 | // ID assigned by protobuf-global-extension-registry@google.com for gRPC-Gateway project. 26 | // 27 | // All IDs are the same, as assigned. It is okay that they are the same, as they extend 28 | // different descriptor messages. 29 | Schema openapiv2_schema = 1042; 30 | } 31 | extend google.protobuf.ServiceOptions { 32 | // ID assigned by protobuf-global-extension-registry@google.com for gRPC-Gateway project. 33 | // 34 | // All IDs are the same, as assigned. It is okay that they are the same, as they extend 35 | // different descriptor messages. 36 | Tag openapiv2_tag = 1042; 37 | } 38 | extend google.protobuf.FieldOptions { 39 | // ID assigned by protobuf-global-extension-registry@google.com for gRPC-Gateway project. 40 | // 41 | // All IDs are the same, as assigned. It is okay that they are the same, as they extend 42 | // different descriptor messages. 43 | JSONSchema openapiv2_field = 1042; 44 | } -------------------------------------------------------------------------------- /example/web/fiber/docs/swagger.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "description": "This is a sample rk-demo server.", 5 | "title": "Swagger Example API", 6 | "termsOfService": "http://swagger.io/terms/", 7 | "contact": { 8 | "name": "API Support", 9 | "url": "http://www.swagger.io/support", 10 | "email": "support@swagger.io" 11 | }, 12 | "license": { 13 | "name": "Apache 2.0", 14 | "url": "http://www.apache.org/licenses/LICENSE-2.0.html" 15 | }, 16 | "version": "1.0" 17 | }, 18 | "paths": { 19 | "/v1/greeter": { 20 | "get": { 21 | "produces": [ 22 | "application/json" 23 | ], 24 | "tags": [ 25 | "Hello" 26 | ], 27 | "summary": "Greeter", 28 | "operationId": "1", 29 | "parameters": [ 30 | { 31 | "type": "string", 32 | "description": "name", 33 | "name": "name", 34 | "in": "query", 35 | "required": true 36 | } 37 | ], 38 | "responses": { 39 | "200": { 40 | "description": "OK", 41 | "schema": { 42 | "$ref": "#/definitions/main.GreeterResponse" 43 | } 44 | } 45 | } 46 | } 47 | } 48 | }, 49 | "definitions": { 50 | "main.GreeterResponse": { 51 | "type": "object", 52 | "properties": { 53 | "message": { 54 | "type": "string" 55 | } 56 | } 57 | } 58 | }, 59 | "securityDefinitions": { 60 | "BasicAuth": { 61 | "type": "basic" 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /example/web/gin/docs/swagger.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "description": "This is a sample rk-demo server.", 5 | "title": "Swagger Example API", 6 | "termsOfService": "http://swagger.io/terms/", 7 | "contact": { 8 | "name": "API Support", 9 | "url": "http://www.swagger.io/support", 10 | "email": "support@swagger.io" 11 | }, 12 | "license": { 13 | "name": "Apache 2.0", 14 | "url": "http://www.apache.org/licenses/LICENSE-2.0.html" 15 | }, 16 | "version": "1.0" 17 | }, 18 | "paths": { 19 | "/v1/greeter": { 20 | "get": { 21 | "produces": [ 22 | "application/json" 23 | ], 24 | "tags": [ 25 | "Hello" 26 | ], 27 | "summary": "Greeter", 28 | "operationId": "1", 29 | "parameters": [ 30 | { 31 | "type": "string", 32 | "description": "name", 33 | "name": "name", 34 | "in": "query", 35 | "required": true 36 | } 37 | ], 38 | "responses": { 39 | "200": { 40 | "description": "OK", 41 | "schema": { 42 | "$ref": "#/definitions/main.GreeterResponse" 43 | } 44 | } 45 | } 46 | } 47 | } 48 | }, 49 | "definitions": { 50 | "main.GreeterResponse": { 51 | "type": "object", 52 | "properties": { 53 | "message": { 54 | "type": "string" 55 | } 56 | } 57 | } 58 | }, 59 | "securityDefinitions": { 60 | "BasicAuth": { 61 | "type": "basic" 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /example/web/zero/docs/swagger.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "description": "This is a sample rk-demo server.", 5 | "title": "Swagger Example API", 6 | "termsOfService": "http://swagger.io/terms/", 7 | "contact": { 8 | "name": "API Support", 9 | "url": "http://www.swagger.io/support", 10 | "email": "support@swagger.io" 11 | }, 12 | "license": { 13 | "name": "Apache 2.0", 14 | "url": "http://www.apache.org/licenses/LICENSE-2.0.html" 15 | }, 16 | "version": "1.0" 17 | }, 18 | "paths": { 19 | "/v1/greeter": { 20 | "get": { 21 | "produces": [ 22 | "application/json" 23 | ], 24 | "tags": [ 25 | "Hello" 26 | ], 27 | "summary": "Greeter", 28 | "operationId": "1", 29 | "parameters": [ 30 | { 31 | "type": "string", 32 | "description": "name", 33 | "name": "name", 34 | "in": "query", 35 | "required": true 36 | } 37 | ], 38 | "responses": { 39 | "200": { 40 | "description": "OK", 41 | "schema": { 42 | "$ref": "#/definitions/main.GreeterResponse" 43 | } 44 | } 45 | } 46 | } 47 | } 48 | }, 49 | "definitions": { 50 | "main.GreeterResponse": { 51 | "type": "object", 52 | "properties": { 53 | "message": { 54 | "type": "string" 55 | } 56 | } 57 | } 58 | }, 59 | "securityDefinitions": { 60 | "BasicAuth": { 61 | "type": "basic" 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /example/database/redis/boot.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | gin: 3 | - name: server 4 | enabled: true 5 | port: 8080 6 | redis: 7 | - name: redis # Required 8 | enabled: true # Required 9 | addrs: ["localhost:6379"] # Required, One addr is for single, multiple is for cluster 10 | # domain: "*" # Optional 11 | # description: "" # Optional 12 | # 13 | # # For HA 14 | # mansterName: "" # Optional, required when connecting to Sentinel(HA) 15 | # sentinelPass: "" # Optional, default: "" 16 | # 17 | # # For cluster 18 | # maxRedirects: 3 # Optional, default: 3 19 | # readOnly: false # Optional, default: false 20 | # routeByLatency: false # Optional, default: false 21 | # routeRandomly: false # Optional, default: false 22 | # 23 | # # Common options 24 | # db: 0 # Optional, default: 0 25 | # user: "" # Optional, default: "" 26 | # pass: "" # Optional, default: "" 27 | # maxRetries: 3 # Optional, default: 3 28 | # minRetryBackoffMs: 8 # Optional, default: 8 29 | # maxRetryBackoffMs: 512 # Optional, default: 512 30 | # dialTimeoutMs: 5000 # Optional, default: 5000 (5 seconds) 31 | # readTimeoutMs: 3000 # Optional, default: 3000 (3 seconds) 32 | # writeTimeoutMs: 1 # Optional, default: 3000 (3 seconds) 33 | # poolFIFO: false # Optional, default: false 34 | # poolSize: 10 # Optional, default: 10 35 | # minIdleConn: 0 # Optional, default: 0 36 | # maxConnAgeMs: 0 # Optional, default: no aged connection 37 | # poolTimeoutMs: 1300 # Optional, default: 1300 (1.3 seconds) 38 | # idleTimeoutMs: 1 # Optional, default: 5 minutes 39 | # idleCheckFrequencyMs: 1 # Optional, default: 1 minutes 40 | # 41 | # loggerEntry: "" # Optional, default: default logger with STDOUT 42 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/rookie-ninja/rk-boot/v2 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/rookie-ninja/rk-entry/v2 v2.2.22 7 | github.com/stretchr/testify v1.8.4 8 | go.uber.org/zap v1.25.0 9 | ) 10 | 11 | require ( 12 | github.com/beorn7/perks v1.0.1 // indirect 13 | github.com/cespare/xxhash/v2 v2.2.0 // indirect 14 | github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect 15 | github.com/fsnotify/fsnotify v1.6.0 // indirect 16 | github.com/golang-jwt/jwt/v4 v4.5.0 // indirect 17 | github.com/golang/protobuf v1.5.3 // indirect 18 | github.com/google/uuid v1.4.0 // indirect 19 | github.com/hashicorp/hcl v1.0.0 // indirect 20 | github.com/magiconair/properties v1.8.7 // indirect 21 | github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect 22 | github.com/mitchellh/mapstructure v1.5.0 // indirect 23 | github.com/pelletier/go-toml/v2 v2.1.0 // indirect 24 | github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect 25 | github.com/prometheus/client_golang v1.17.0 // indirect 26 | github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect 27 | github.com/prometheus/common v0.44.0 // indirect 28 | github.com/prometheus/procfs v0.11.1 // indirect 29 | github.com/rookie-ninja/rk-logger v1.2.13 // indirect 30 | github.com/rookie-ninja/rk-query v1.2.14 // indirect 31 | github.com/sagikazarmark/locafero v0.3.0 // indirect 32 | github.com/sagikazarmark/slog-shim v0.1.0 // indirect 33 | github.com/sourcegraph/conc v0.3.0 // indirect 34 | github.com/spf13/afero v1.10.0 // indirect 35 | github.com/spf13/cast v1.5.1 // indirect 36 | github.com/spf13/pflag v1.0.5 // indirect 37 | github.com/spf13/viper v1.17.0 // indirect 38 | github.com/subosito/gotenv v1.6.0 // indirect 39 | go.uber.org/atomic v1.11.0 // indirect 40 | go.uber.org/multierr v1.10.0 // indirect 41 | golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect 42 | golang.org/x/sys v0.12.0 // indirect 43 | golang.org/x/text v0.13.0 // indirect 44 | google.golang.org/protobuf v1.31.0 // indirect 45 | gopkg.in/ini.v1 v1.67.0 // indirect 46 | gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect 47 | gopkg.in/yaml.v2 v2.4.0 // indirect 48 | gopkg.in/yaml.v3 v3.0.1 // indirect 49 | ) 50 | -------------------------------------------------------------------------------- /example/middleware/jwt/gin/docs/swagger.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "description": "This is a sample rk-boot server.", 5 | "title": "Swagger Example API", 6 | "termsOfService": "http://swagger.io/terms/", 7 | "contact": { 8 | "name": "API Support", 9 | "url": "http://www.swagger.io/support", 10 | "email": "support@swagger.io" 11 | }, 12 | "license": { 13 | "name": "Apache 2.0", 14 | "url": "http://www.apache.org/licenses/LICENSE-2.0.html" 15 | }, 16 | "version": "1.0" 17 | }, 18 | "paths": { 19 | "/v1/login": { 20 | "get": { 21 | "security": [ 22 | { 23 | "JWT": [] 24 | } 25 | ], 26 | "produces": [ 27 | "application/json" 28 | ], 29 | "tags": [ 30 | "JWT" 31 | ], 32 | "summary": "Login", 33 | "operationId": "1", 34 | "parameters": [ 35 | { 36 | "type": "string", 37 | "description": "name", 38 | "name": "name", 39 | "in": "query", 40 | "required": true 41 | } 42 | ], 43 | "responses": {} 44 | } 45 | }, 46 | "/v1/whoami": { 47 | "get": { 48 | "security": [ 49 | { 50 | "JWT": [] 51 | } 52 | ], 53 | "produces": [ 54 | "application/json" 55 | ], 56 | "tags": [ 57 | "JWT" 58 | ], 59 | "summary": "WhoAmI", 60 | "operationId": "2", 61 | "responses": {} 62 | } 63 | } 64 | }, 65 | "securityDefinitions": { 66 | "JWT": { 67 | "type": "apiKey", 68 | "name": "Authorization", 69 | "in": "header" 70 | } 71 | } 72 | } -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | **Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)* 4 | 5 | - [Contributing](#contributing) 6 | - [Setup](#setup) 7 | - [Making Changes](#making-changes) 8 | 9 | 10 | 11 | # Contributing 12 | If you'd like to add new features, please [open an issue][open-issue] 13 | describing your proposal — discussing feature changes ahead of time makes 14 | pull request review much smoother. In your issue, pull request, and any other 15 | communications, please remember to treat your fellow contributors with 16 | respect! We take our [code of conduct](CODE_OF_CONDUCT.md) seriously. 17 | 18 | ## Setup 19 | 20 | [Fork][fork], then clone the repository: 21 | 22 | ``` 23 | git clone https://github.com/rookie-ninja/rk-boot.git 24 | cd rk-boot 25 | git remote add upstream https://github.com/rookie-ninja/rk-boot.git 26 | git fetch upstream 27 | ``` 28 | 29 | Install rk-boot's dependencies: 30 | 31 | ``` 32 | go mod tidy 33 | ``` 34 | 35 | ## Making Changes 36 | 37 | Start by creating a new branch for your changes: 38 | 39 | ``` 40 | git checkout master 41 | git fetch upstream 42 | git rebase upstream/master 43 | git checkout -b cool_new_feature 44 | ``` 45 | 46 | Make your changes, then ensure that `make lint` and `make test` still pass. If 47 | you're satisfied with your changes, push them to your fork. 48 | 49 | ``` 50 | git push origin cool_new_feature 51 | ``` 52 | 53 | Then use the GitHub UI to open a pull request. 54 | 55 | At this point, you're waiting on us to review your changes. We *try* to respond 56 | to issues and pull requests within a few business days, and we may suggest some 57 | improvements or alternatives. Once your changes are approved, one of the 58 | project maintainers will merge them. 59 | 60 | We're much more likely to approve your changes if you: 61 | 62 | * Add tests for new functionality. 63 | * Write a [good commit message][commit-message]. 64 | * Maintain backward compatibility. 65 | 66 | [fork]: https://github.com/rookie-ninja/rk-boot/fork 67 | [open-issue]: https://github.com/rookie-ninja/rk-boot/issues/new 68 | [cla]: https://cla-assistant.io/rookie-ninja/rk-boot 69 | [commit-message]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html -------------------------------------------------------------------------------- /example/web/grpc/third-party/googleapis/google/api/httpbody.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Google LLC. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | syntax = "proto3"; 17 | 18 | package google.api; 19 | 20 | import "google/protobuf/any.proto"; 21 | 22 | option cc_enable_arenas = true; 23 | option go_package = "google.golang.org/genproto/googleapis/api/httpbody;httpbody"; 24 | option java_multiple_files = true; 25 | option java_outer_classname = "HttpBodyProto"; 26 | option java_package = "com.google.api"; 27 | option objc_class_prefix = "GAPI"; 28 | 29 | // Message that represents an arbitrary HTTP body. It should only be used for 30 | // payload formats that can't be represented as JSON, such as raw binary or 31 | // an HTML page. 32 | // 33 | // 34 | // This message can be used both in streaming and non-streaming API methods in 35 | // the request as well as the response. 36 | // 37 | // It can be used as a top-level request field, which is convenient if one 38 | // wants to extract parameters from either the URL or HTTP template into the 39 | // request fields and also want access to the raw HTTP body. 40 | // 41 | // Example: 42 | // 43 | // message GetResourceRequest { 44 | // // A unique request id. 45 | // string request_id = 1; 46 | // 47 | // // The raw HTTP body is bound to this field. 48 | // google.api.HttpBody http_body = 2; 49 | // } 50 | // 51 | // service ResourceService { 52 | // rpc GetResource(GetResourceRequest) returns (google.api.HttpBody); 53 | // rpc UpdateResource(google.api.HttpBody) returns 54 | // (google.protobuf.Empty); 55 | // } 56 | // 57 | // Example with streaming methods: 58 | // 59 | // service CaldavService { 60 | // rpc GetCalendar(stream google.api.HttpBody) 61 | // returns (stream google.api.HttpBody); 62 | // rpc UpdateCalendar(stream google.api.HttpBody) 63 | // returns (stream google.api.HttpBody); 64 | // } 65 | // 66 | // Use of this type only changes how the request and response bodies are 67 | // handled, all other features will continue to work unchanged. 68 | message HttpBody { 69 | // The HTTP Content-Type header value specifying the content type of the body. 70 | string content_type = 1; 71 | 72 | // The HTTP request/response body as raw binary. 73 | bytes data = 2; 74 | 75 | // Application specific response metadata. Must be set in the first response 76 | // for streaming APIs. 77 | repeated google.protobuf.Any extensions = 3; 78 | } -------------------------------------------------------------------------------- /example/database/clickhouse/main.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 rookie-ninja 2 | // 3 | // Use of this source code is governed by an Apache-style 4 | // license that can be found in the LICENSE file. 5 | package main 6 | 7 | import ( 8 | "context" 9 | "github.com/gin-gonic/gin" 10 | "github.com/rookie-ninja/rk-boot/v2" 11 | "github.com/rookie-ninja/rk-db/clickhouse" 12 | "github.com/rookie-ninja/rk-gin/v2/boot" 13 | "github.com/rs/xid" 14 | "gorm.io/gorm" 15 | "net/http" 16 | "time" 17 | ) 18 | 19 | var userDb *gorm.DB 20 | 21 | func main() { 22 | boot := rkboot.NewBoot() 23 | 24 | boot.Bootstrap(context.TODO()) 25 | 26 | // Auto migrate database and init global userDb variable 27 | clickHouseEntry := rkclickhouse.GetClickHouseEntry("user-db") 28 | userDb = clickHouseEntry.GetDB("user") 29 | if !userDb.DryRun { 30 | userDb.AutoMigrate(&User{}) 31 | } 32 | 33 | // Register APIs 34 | ginEntry := rkgin.GetGinEntry("user-service") 35 | ginEntry.Router.GET("/v1/user", ListUsers) 36 | ginEntry.Router.GET("/v1/user/:id", GetUser) 37 | ginEntry.Router.PUT("/v1/user", CreateUser) 38 | ginEntry.Router.POST("/v1/user/:id", UpdateUser) 39 | ginEntry.Router.DELETE("/v1/user/:id", DeleteUser) 40 | 41 | boot.WaitForShutdownSig(context.TODO()) 42 | } 43 | 44 | // ************************************* 45 | // *************** Model *************** 46 | // ************************************* 47 | 48 | type Base struct { 49 | CreatedAt time.Time `yaml:"-" json:"-"` 50 | UpdatedAt time.Time `yaml:"-" json:"-"` 51 | } 52 | 53 | type User struct { 54 | Base 55 | Id string `yaml:"id" json:"id"` 56 | Name string `yaml:"name" json:"name"` 57 | } 58 | 59 | func ListUsers(ctx *gin.Context) { 60 | userList := make([]*User, 0) 61 | res := userDb.Find(&userList) 62 | 63 | if res.Error != nil { 64 | ctx.JSON(http.StatusInternalServerError, res.Error) 65 | return 66 | } 67 | ctx.JSON(http.StatusOK, userList) 68 | } 69 | 70 | func GetUser(ctx *gin.Context) { 71 | uid := ctx.Param("id") 72 | user := &User{} 73 | res := userDb.Find(user, "id = ?", uid) 74 | 75 | if res.Error != nil { 76 | ctx.JSON(http.StatusInternalServerError, res.Error) 77 | return 78 | } 79 | ctx.JSON(http.StatusOK, user) 80 | } 81 | 82 | func CreateUser(ctx *gin.Context) { 83 | user := &User{ 84 | Id: xid.New().String(), 85 | Name: ctx.Query("name"), 86 | } 87 | 88 | res := userDb.Create(user) 89 | 90 | if res.Error != nil { 91 | ctx.JSON(http.StatusInternalServerError, res.Error) 92 | return 93 | } 94 | ctx.JSON(http.StatusOK, user) 95 | } 96 | 97 | func UpdateUser(ctx *gin.Context) { 98 | uid := ctx.Param("id") 99 | user := &User{ 100 | Id: uid, 101 | Name: ctx.Query("name"), 102 | } 103 | 104 | res := userDb.Where("id = ?", uid).Updates(user) 105 | 106 | if res.Error != nil { 107 | ctx.JSON(http.StatusInternalServerError, res.Error) 108 | return 109 | } 110 | 111 | ctx.JSON(http.StatusOK, user) 112 | } 113 | 114 | func DeleteUser(ctx *gin.Context) { 115 | uid := ctx.Param("id") 116 | 117 | res := userDb.Delete(&User{}, "id = ?", uid) 118 | 119 | if res.Error != nil { 120 | ctx.JSON(http.StatusInternalServerError, res.Error) 121 | return 122 | } 123 | 124 | ctx.String(http.StatusOK, "success") 125 | } 126 | -------------------------------------------------------------------------------- /example/middleware/jwt/gin/main.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 rookie-ninja 2 | // 3 | // Use of this source code is governed by an Apache-style 4 | // license that can be found in the LICENSE file. 5 | 6 | package main 7 | 8 | import ( 9 | "context" 10 | "encoding/json" 11 | "fmt" 12 | "github.com/gin-gonic/gin" 13 | "github.com/golang-jwt/jwt/v4" 14 | "github.com/rookie-ninja/rk-boot/v2" 15 | "github.com/rookie-ninja/rk-entry/v2/entry" 16 | "github.com/rookie-ninja/rk-gin/v2/boot" 17 | "github.com/rookie-ninja/rk-gin/v2/middleware/context" 18 | "net/http" 19 | "time" 20 | ) 21 | 22 | // @title Swagger Example API 23 | // @version 1.0 24 | // @description This is a sample rk-boot server. 25 | // @termsOfService http://swagger.io/terms/ 26 | 27 | // @securityDefinitions.apikey JWT 28 | // @in header 29 | // @name Authorization 30 | 31 | // @contact.name API Support 32 | // @contact.url http://www.swagger.io/support 33 | // @contact.email support@swagger.io 34 | 35 | // @license.name Apache 2.0 36 | // @license.url http://www.apache.org/licenses/LICENSE-2.0.html 37 | func main() { 38 | // Create a new boot instance. 39 | boot := rkboot.NewBoot() 40 | 41 | // Register handler 42 | entry := rkgin.GetGinEntry("greeter") 43 | entry.Router.GET("/v1/login", Login) 44 | entry.Router.GET("/v1/whoami", WhoAmI) 45 | 46 | // Bootstrap 47 | boot.Bootstrap(context.TODO()) 48 | 49 | boot.WaitForShutdownSig(context.TODO()) 50 | } 51 | 52 | // CustomClaims defines JWT claims 53 | type CustomClaims struct { 54 | UserName string `json:"uname"` 55 | jwt.RegisteredClaims 56 | } 57 | 58 | // Login handler 59 | // @Summary Login 60 | // @Id 1 61 | // @Tags JWT 62 | // @version 1.0 63 | // @Security JWT 64 | // @Param name query string true "name" 65 | // @produce application/json 66 | // @Router /v1/login [get] 67 | func Login(ctx *gin.Context) { 68 | // Simply generate JWT token from user provided name for demo 69 | userName := ctx.Query("name") 70 | 71 | now := time.Now() 72 | claims := CustomClaims{ 73 | UserName: userName, 74 | RegisteredClaims: jwt.RegisteredClaims{ 75 | ExpiresAt: jwt.NewNumericDate(now.Add(30 * time.Minute)), 76 | IssuedAt: jwt.NewNumericDate(now), 77 | NotBefore: jwt.NewNumericDate(now), 78 | Issuer: "rk-boot", 79 | }, 80 | } 81 | 82 | // By default, JWT middleware will create a new SignerEntry with the same name of Gin Entry 83 | // default signer entry will use symmetric algorithm (HS256) with token of (rk jwt key) 84 | // refer rkmidjwt.NewOptionSet 85 | signerEntry := rkentry.GlobalAppCtx.GetSignerJwtEntry("greeter") 86 | 87 | res, _ := signerEntry.SignJwt(claims) 88 | ctx.JSON(http.StatusOK, map[string]string{ 89 | "JwtToken": res, 90 | }) 91 | } 92 | 93 | // WhoAmI handler 94 | // @Summary WhoAmI 95 | // @Id 2 96 | // @Tags JWT 97 | // @version 1.0 98 | // @Security JWT 99 | // @produce application/json 100 | // @Router /v1/whoami [get] 101 | func WhoAmI(ctx *gin.Context) { 102 | // 1: get JWT token from context which injected into context by middleware 103 | token := rkginctx.GetJwtToken(ctx) 104 | 105 | // convert claim to custom claim 106 | claims := &CustomClaims{} 107 | bytes, _ := json.Marshal(token.Claims) 108 | json.Unmarshal(bytes, claims) 109 | 110 | ctx.JSON(http.StatusOK, map[string]string{ 111 | "Message": fmt.Sprintf("Your name is %s", claims.UserName), 112 | }) 113 | } 114 | -------------------------------------------------------------------------------- /example/web/mux/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/rookie-ninja/rk-demo 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/rookie-ninja/rk-boot/v2 v2.1.2 7 | github.com/rookie-ninja/rk-mux v1.2.17 8 | ) 9 | 10 | require ( 11 | github.com/benbjohnson/clock v1.3.0 // indirect 12 | github.com/beorn7/perks v1.0.1 // indirect 13 | github.com/cenkalti/backoff/v4 v4.2.1 // indirect 14 | github.com/cespare/xxhash/v2 v2.2.0 // indirect 15 | github.com/fsnotify/fsnotify v1.6.0 // indirect 16 | github.com/go-logr/logr v1.2.4 // indirect 17 | github.com/go-logr/stdr v1.2.2 // indirect 18 | github.com/golang-jwt/jwt/v4 v4.5.0 // indirect 19 | github.com/golang/protobuf v1.5.3 // indirect 20 | github.com/google/uuid v1.4.0 // indirect 21 | github.com/gorilla/mux v1.8.0 // indirect 22 | github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect 23 | github.com/hashicorp/hcl v1.0.0 // indirect 24 | github.com/magiconair/properties v1.8.7 // indirect 25 | github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect 26 | github.com/mitchellh/mapstructure v1.5.0 // indirect 27 | github.com/openzipkin/zipkin-go v0.4.2 // indirect 28 | github.com/pelletier/go-toml/v2 v2.1.0 // indirect 29 | github.com/prometheus/client_golang v1.17.0 // indirect 30 | github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect 31 | github.com/prometheus/common v0.44.0 // indirect 32 | github.com/prometheus/procfs v0.11.1 // indirect 33 | github.com/rookie-ninja/rk-entry/v2 v2.2.20 // indirect 34 | github.com/rookie-ninja/rk-logger v1.2.13 // indirect 35 | github.com/rookie-ninja/rk-query v1.2.14 // indirect 36 | github.com/spf13/afero v1.10.0 // indirect 37 | github.com/spf13/cast v1.5.1 // indirect 38 | github.com/spf13/jwalterweatherman v1.1.0 // indirect 39 | github.com/spf13/pflag v1.0.5 // indirect 40 | github.com/spf13/viper v1.17.0 // indirect 41 | github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a // indirect 42 | github.com/subosito/gotenv v1.6.0 // indirect 43 | go.opentelemetry.io/contrib v1.19.0 // indirect 44 | go.opentelemetry.io/otel v1.18.0 // indirect 45 | go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.18.0 // indirect 46 | go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.18.0 // indirect 47 | go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.18.0 // indirect 48 | go.opentelemetry.io/otel/exporters/zipkin v1.18.0 // indirect 49 | go.opentelemetry.io/otel/metric v1.18.0 // indirect 50 | go.opentelemetry.io/otel/sdk v1.18.0 // indirect 51 | go.opentelemetry.io/otel/trace v1.18.0 // indirect 52 | go.opentelemetry.io/proto/otlp v1.0.0 // indirect 53 | go.uber.org/atomic v1.11.0 // indirect 54 | go.uber.org/multierr v1.10.0 // indirect 55 | go.uber.org/ratelimit v0.3.0 // indirect 56 | go.uber.org/zap v1.25.0 // indirect 57 | golang.org/x/net v0.15.0 // indirect 58 | golang.org/x/sys v0.12.0 // indirect 59 | golang.org/x/text v0.13.0 // indirect 60 | google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb // indirect 61 | google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect 62 | google.golang.org/grpc v1.58.2 // indirect 63 | google.golang.org/protobuf v1.31.0 // indirect 64 | gopkg.in/ini.v1 v1.67.0 // indirect 65 | gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect 66 | gopkg.in/yaml.v2 v2.4.0 // indirect 67 | gopkg.in/yaml.v3 v3.0.1 // indirect 68 | ) 69 | 70 | replace github.com/rookie-ninja/rk-boot/v2 => ../../../ 71 | -------------------------------------------------------------------------------- /example/web/mux/README.md: -------------------------------------------------------------------------------- 1 | # Example 2 | Middleware & bootstrapper designed for [gorilla/mux](https://github.com/gorilla/mux) web framework. 3 | 4 | ## Documentation 5 | - [Github](https://github.com/rookie-ninja/rk-mux) 6 | - [Official Docs]() will be updated for v2 soon 7 | 8 | ![image](docs/img/mux-arch.png) 9 | 10 | ## Installation 11 | - rk-boot: Bootstrapper base 12 | - rk-mux: Bootstrapper for [gorilla/mux](https://github.com/gorilla/mux) 13 | 14 | ```shell 15 | go get github.com/rookie-ninja/rk-boot/v2 16 | go get github.com/rookie-ninja/rk-mux 17 | ``` 18 | 19 | ## Quick start 20 | ### 1.Create boot.yaml 21 | ```yaml 22 | --- 23 | mux: 24 | - name: greeter # Required 25 | port: 8080 # Required 26 | enabled: true # Required 27 | commonService: 28 | enabled: true # Optional, default: false 29 | sw: 30 | enabled: true # Optional, default: false 31 | docs: 32 | enabled: true # Optional, default: false 33 | ``` 34 | 35 | ### 2.Create main.go 36 | ```go 37 | // Copyright (c) 2021 rookie-ninja 38 | // 39 | // Use of this source code is governed by an Apache-style 40 | // license that can be found in the LICENSE file. 41 | package main 42 | 43 | import ( 44 | "context" 45 | _ "embed" 46 | "fmt" 47 | "github.com/rookie-ninja/rk-boot/v2" 48 | "github.com/rookie-ninja/rk-mux/boot" 49 | "github.com/rookie-ninja/rk-mux/middleware" 50 | "net/http" 51 | ) 52 | 53 | // @title RK Swagger for Mux 54 | // @version 1.0 55 | // @description This is a greeter service with rk-boot. 56 | func main() { 57 | // Create a new boot instance. 58 | boot := rkboot.NewBoot() 59 | 60 | // Get MuxEntry 61 | muxEntry := rkmux.GetMuxEntry("greeter") 62 | // Use *mux.Router adding handler. 63 | muxEntry.Router.NewRoute().Path("/v1/greeter").HandlerFunc(Greeter) 64 | 65 | // Bootstrap 66 | boot.Bootstrap(context.TODO()) 67 | 68 | boot.WaitForShutdownSig(context.TODO()) 69 | } 70 | 71 | // Greeter handler 72 | // @Summary Greeter service 73 | // @Id 1 74 | // @version 1.0 75 | // @produce application/json 76 | // @Param name query string true "Input name" 77 | // @Success 200 {object} GreeterResponse 78 | // @Router /v1/greeter [get] 79 | func Greeter(writer http.ResponseWriter, req *http.Request) { 80 | rkmuxmid.WriteJson(writer, http.StatusOK, &GreeterResponse{ 81 | Message: fmt.Sprintf("Hello %s!", req.URL.Query().Get("name")), 82 | }) 83 | } 84 | 85 | type GreeterResponse struct { 86 | Message string 87 | } 88 | ``` 89 | 90 | ### 3.Start server 91 | 92 | ```go 93 | $ go run main.go 94 | ``` 95 | 96 | ### 4.Validation 97 | - Call API: 98 | 99 | ```shell script 100 | $ curl -X GET localhost:8080/v1/greeter?name=rk-dev 101 | {"Message":"Hello rk-dev!"} 102 | 103 | $ curl -X GET localhost:8080/rk/v1/ready 104 | { 105 | "ready": true 106 | } 107 | 108 | $ curl -X GET localhost:8080/rk/v1/alive 109 | { 110 | "alive": true 111 | } 112 | ``` 113 | 114 | - Swagger UI: [http://localhost:8080/sw](http://localhost:8080/sw) 115 | 116 | ![image](docs/img/simple-sw.png) 117 | 118 | - Docs UI via: [http://localhost:8080/docs](http://localhost:8080/docs) 119 | 120 | ![image](docs/img/simple-docs.png) 121 | 122 | -------------------------------------------------------------------------------- /example/web/grpc/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/rookie-ninja/rk-demo 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 7 | github.com/rookie-ninja/rk-boot/v2 v2.1.2 8 | github.com/rookie-ninja/rk-grpc/v2 v2.2.21 9 | google.golang.org/grpc v1.58.2 10 | google.golang.org/protobuf v1.31.0 11 | ) 12 | 13 | require ( 14 | github.com/benbjohnson/clock v1.3.0 // indirect 15 | github.com/beorn7/perks v1.0.1 // indirect 16 | github.com/cenkalti/backoff/v4 v4.2.1 // indirect 17 | github.com/cespare/xxhash/v2 v2.2.0 // indirect 18 | github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect 19 | github.com/fsnotify/fsnotify v1.6.0 // indirect 20 | github.com/go-logr/logr v1.2.4 // indirect 21 | github.com/go-logr/stdr v1.2.2 // indirect 22 | github.com/golang-jwt/jwt/v4 v4.5.0 // indirect 23 | github.com/golang/protobuf v1.5.3 // indirect 24 | github.com/google/uuid v1.4.0 // indirect 25 | github.com/hashicorp/hcl v1.0.0 // indirect 26 | github.com/improbable-eng/grpc-web v0.15.0 // indirect 27 | github.com/klauspost/compress v1.17.0 // indirect 28 | github.com/magiconair/properties v1.8.7 // indirect 29 | github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect 30 | github.com/mitchellh/mapstructure v1.5.0 // indirect 31 | github.com/openzipkin/zipkin-go v0.4.2 // indirect 32 | github.com/pelletier/go-toml/v2 v2.1.0 // indirect 33 | github.com/prometheus/client_golang v1.17.0 // indirect 34 | github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect 35 | github.com/prometheus/common v0.44.0 // indirect 36 | github.com/prometheus/procfs v0.11.1 // indirect 37 | github.com/rookie-ninja/rk-entry/v2 v2.2.20 // indirect 38 | github.com/rookie-ninja/rk-logger v1.2.13 // indirect 39 | github.com/rookie-ninja/rk-query v1.2.14 // indirect 40 | github.com/rs/cors v1.7.0 // indirect 41 | github.com/soheilhy/cmux v0.1.5 // indirect 42 | github.com/spf13/afero v1.10.0 // indirect 43 | github.com/spf13/cast v1.5.1 // indirect 44 | github.com/spf13/jwalterweatherman v1.1.0 // indirect 45 | github.com/spf13/pflag v1.0.5 // indirect 46 | github.com/spf13/viper v1.17.0 // indirect 47 | github.com/subosito/gotenv v1.6.0 // indirect 48 | go.opentelemetry.io/contrib v1.19.0 // indirect 49 | go.opentelemetry.io/otel v1.18.0 // indirect 50 | go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.18.0 // indirect 51 | go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.18.0 // indirect 52 | go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.18.0 // indirect 53 | go.opentelemetry.io/otel/exporters/zipkin v1.18.0 // indirect 54 | go.opentelemetry.io/otel/metric v1.18.0 // indirect 55 | go.opentelemetry.io/otel/sdk v1.18.0 // indirect 56 | go.opentelemetry.io/otel/trace v1.18.0 // indirect 57 | go.opentelemetry.io/proto/otlp v1.0.0 // indirect 58 | go.uber.org/atomic v1.11.0 // indirect 59 | go.uber.org/multierr v1.10.0 // indirect 60 | go.uber.org/ratelimit v0.3.0 // indirect 61 | go.uber.org/zap v1.25.0 // indirect 62 | golang.org/x/net v0.15.0 // indirect 63 | golang.org/x/sys v0.12.0 // indirect 64 | golang.org/x/text v0.13.0 // indirect 65 | google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb // indirect 66 | google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect 67 | gopkg.in/ini.v1 v1.67.0 // indirect 68 | gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect 69 | gopkg.in/yaml.v2 v2.4.0 // indirect 70 | gopkg.in/yaml.v3 v3.0.1 // indirect 71 | nhooyr.io/websocket v1.8.6 // indirect 72 | ) 73 | 74 | replace github.com/rookie-ninja/rk-boot/v2 => ../../../ 75 | -------------------------------------------------------------------------------- /example/database/postgres/main.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 rookie-ninja 2 | // 3 | // Use of this source code is governed by an Apache-style 4 | // license that can be found in the LICENSE file. 5 | package main 6 | 7 | import ( 8 | "context" 9 | "github.com/gin-gonic/gin" 10 | "github.com/rookie-ninja/rk-boot/v2" 11 | "github.com/rookie-ninja/rk-db/postgres" 12 | "github.com/rookie-ninja/rk-gin/v2/boot" 13 | "gorm.io/gorm" 14 | "net/http" 15 | "strconv" 16 | "time" 17 | ) 18 | 19 | var userDb *gorm.DB 20 | 21 | func main() { 22 | boot := rkboot.NewBoot() 23 | 24 | boot.Bootstrap(context.TODO()) 25 | 26 | // Auto migrate database and init global userDb variable 27 | pgEntry := rkpostgres.GetPostgresEntry("user-db") 28 | userDb = pgEntry.GetDB("user") 29 | if !userDb.DryRun { 30 | userDb.AutoMigrate(&User{}) 31 | } 32 | 33 | // Register APIs 34 | ginEntry := rkgin.GetGinEntry("user-service") 35 | ginEntry.Router.GET("/v1/user", ListUsers) 36 | ginEntry.Router.GET("/v1/user/:id", GetUser) 37 | ginEntry.Router.PUT("/v1/user", CreateUser) 38 | ginEntry.Router.POST("/v1/user/:id", UpdateUser) 39 | ginEntry.Router.DELETE("/v1/user/:id", DeleteUser) 40 | 41 | boot.WaitForShutdownSig(context.TODO()) 42 | } 43 | 44 | // ************************************* 45 | // *************** Model *************** 46 | // ************************************* 47 | 48 | type Base struct { 49 | CreatedAt time.Time `yaml:"-" json:"-"` 50 | UpdatedAt time.Time `yaml:"-" json:"-"` 51 | DeletedAt gorm.DeletedAt `yaml:"-" json:"-" gorm:"index"` 52 | } 53 | 54 | type User struct { 55 | Base 56 | Id int `yaml:"id" json:"id" gorm:"primaryKey"` 57 | Name string `yaml:"name" json:"name"` 58 | } 59 | 60 | func ListUsers(ctx *gin.Context) { 61 | userList := make([]*User, 0) 62 | res := userDb.Find(&userList) 63 | 64 | if res.Error != nil { 65 | ctx.JSON(http.StatusInternalServerError, res.Error) 66 | return 67 | } 68 | ctx.JSON(http.StatusOK, userList) 69 | } 70 | 71 | func GetUser(ctx *gin.Context) { 72 | uid := ctx.Param("id") 73 | user := &User{} 74 | res := userDb.Where("id = ?", uid).Find(user) 75 | 76 | if res.Error != nil { 77 | ctx.JSON(http.StatusInternalServerError, res.Error) 78 | return 79 | } 80 | ctx.JSON(http.StatusOK, user) 81 | } 82 | 83 | func CreateUser(ctx *gin.Context) { 84 | user := &User{ 85 | Name: ctx.Query("name"), 86 | } 87 | 88 | res := userDb.Create(user) 89 | 90 | if res.Error != nil { 91 | ctx.JSON(http.StatusInternalServerError, res.Error) 92 | return 93 | } 94 | ctx.JSON(http.StatusOK, user) 95 | } 96 | 97 | func UpdateUser(ctx *gin.Context) { 98 | uid := ctx.Param("id") 99 | user := &User{ 100 | Name: ctx.Query("name"), 101 | } 102 | 103 | res := userDb.Where("id = ?", uid).Updates(user) 104 | 105 | if res.Error != nil { 106 | ctx.JSON(http.StatusInternalServerError, res.Error) 107 | return 108 | } 109 | 110 | if res.RowsAffected < 1 { 111 | ctx.JSON(http.StatusNotFound, "user not found") 112 | return 113 | } 114 | 115 | // get user 116 | userDb.Where("id = ?", uid).Find(user) 117 | 118 | ctx.JSON(http.StatusOK, user) 119 | } 120 | 121 | func DeleteUser(ctx *gin.Context) { 122 | uid, _ := strconv.Atoi(ctx.Param("id")) 123 | res := userDb.Delete(&User{ 124 | Id: uid, 125 | }) 126 | 127 | if res.Error != nil { 128 | ctx.JSON(http.StatusInternalServerError, res.Error) 129 | return 130 | } 131 | 132 | if res.RowsAffected < 1 { 133 | ctx.JSON(http.StatusNotFound, "user not found") 134 | return 135 | } 136 | 137 | ctx.String(http.StatusOK, "success") 138 | } 139 | -------------------------------------------------------------------------------- /example/database/sqlite/main.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 rookie-ninja 2 | // 3 | // Use of this source code is governed by an Apache-style 4 | // license that can be found in the LICENSE file. 5 | package main 6 | 7 | import ( 8 | "context" 9 | "github.com/gin-gonic/gin" 10 | "github.com/rookie-ninja/rk-boot/v2" 11 | "github.com/rookie-ninja/rk-db/sqlite" 12 | "github.com/rookie-ninja/rk-gin/v2/boot" 13 | "gorm.io/gorm" 14 | "net/http" 15 | "strconv" 16 | "time" 17 | ) 18 | 19 | var userDb *gorm.DB 20 | 21 | func main() { 22 | boot := rkboot.NewBoot() 23 | 24 | boot.Bootstrap(context.TODO()) 25 | 26 | // Auto migrate database and init global userDb variable 27 | sqliteEntry := rksqlite.GetSqliteEntry("user-db") 28 | userDb = sqliteEntry.GetDB("user") 29 | if !userDb.DryRun { 30 | userDb.AutoMigrate(&User{}) 31 | } 32 | 33 | // Register APIs 34 | ginEntry := rkgin.GetGinEntry("user-service") 35 | ginEntry.Router.GET("/v1/user", ListUsers) 36 | ginEntry.Router.GET("/v1/user/:id", GetUser) 37 | ginEntry.Router.PUT("/v1/user", CreateUser) 38 | ginEntry.Router.POST("/v1/user/:id", UpdateUser) 39 | ginEntry.Router.DELETE("/v1/user/:id", DeleteUser) 40 | 41 | boot.WaitForShutdownSig(context.TODO()) 42 | } 43 | 44 | // ************************************* 45 | // *************** Model *************** 46 | // ************************************* 47 | 48 | type Base struct { 49 | CreatedAt time.Time `yaml:"-" json:"-"` 50 | UpdatedAt time.Time `yaml:"-" json:"-"` 51 | DeletedAt gorm.DeletedAt `yaml:"-" json:"-" gorm:"index"` 52 | } 53 | 54 | type User struct { 55 | Base 56 | Id int `yaml:"id" json:"id" gorm:"primaryKey"` 57 | Name string `yaml:"name" json:"name"` 58 | } 59 | 60 | func ListUsers(ctx *gin.Context) { 61 | userList := make([]*User, 0) 62 | res := userDb.Find(&userList) 63 | 64 | if res.Error != nil { 65 | ctx.JSON(http.StatusInternalServerError, res.Error) 66 | return 67 | } 68 | ctx.JSON(http.StatusOK, userList) 69 | } 70 | 71 | func GetUser(ctx *gin.Context) { 72 | uid := ctx.Param("id") 73 | user := &User{} 74 | res := userDb.Where("id = ?", uid).Find(user) 75 | 76 | if res.Error != nil { 77 | ctx.JSON(http.StatusInternalServerError, res.Error) 78 | return 79 | } 80 | ctx.JSON(http.StatusOK, user) 81 | } 82 | 83 | func CreateUser(ctx *gin.Context) { 84 | user := &User{ 85 | Name: ctx.Query("name"), 86 | } 87 | 88 | res := userDb.Create(user) 89 | 90 | if res.Error != nil { 91 | ctx.JSON(http.StatusInternalServerError, res.Error) 92 | return 93 | } 94 | ctx.JSON(http.StatusOK, user) 95 | } 96 | 97 | func UpdateUser(ctx *gin.Context) { 98 | uid := ctx.Param("id") 99 | user := &User{ 100 | Name: ctx.Query("name"), 101 | } 102 | 103 | res := userDb.Where("id = ?", uid).Updates(user) 104 | 105 | if res.Error != nil { 106 | ctx.JSON(http.StatusInternalServerError, res.Error) 107 | return 108 | } 109 | 110 | if res.RowsAffected < 1 { 111 | ctx.JSON(http.StatusNotFound, "user not found") 112 | return 113 | } 114 | 115 | // get user 116 | userDb.Where("id = ?", uid).Find(user) 117 | 118 | ctx.JSON(http.StatusOK, user) 119 | } 120 | 121 | func DeleteUser(ctx *gin.Context) { 122 | uid, _ := strconv.Atoi(ctx.Param("id")) 123 | res := userDb.Delete(&User{ 124 | Id: uid, 125 | }) 126 | 127 | if res.Error != nil { 128 | ctx.JSON(http.StatusInternalServerError, res.Error) 129 | return 130 | } 131 | 132 | if res.RowsAffected < 1 { 133 | ctx.JSON(http.StatusNotFound, "user not found") 134 | return 135 | } 136 | 137 | ctx.String(http.StatusOK, "success") 138 | } 139 | -------------------------------------------------------------------------------- /example/web/gin/README.md: -------------------------------------------------------------------------------- 1 | # Example 2 | Middleware & bootstrapper designed for [gin-gonic/gin](https://github.com/gin-gonic/gin) web framework. 3 | 4 | ## Documentation 5 | - [Github](https://github.com/rookie-ninja/rk-gin) 6 | - [Official Docs]() will be updated for v2 soon 7 | 8 | ![image](docs/img/gin-arch.png) 9 | 10 | ## Installation 11 | - rk-boot: Bootstrapper base 12 | - rk-gin: Bootstrapper for [gin-gonic/gin](https://github.com/gin-gonic/gin) 13 | 14 | ```shell 15 | go get github.com/rookie-ninja/rk-boot/v2 16 | go get github.com/rookie-ninja/rk-gin/v2 17 | ``` 18 | 19 | ## Quick start 20 | ### 1.Create boot.yaml 21 | ```yaml 22 | --- 23 | gin: 24 | - name: greeter # Required 25 | port: 8080 # Required 26 | enabled: true # Required 27 | commonService: 28 | enabled: true # Optional, default: false 29 | sw: 30 | enabled: true # Optional, default: false 31 | docs: 32 | enabled: true # Optional, default: false 33 | ``` 34 | 35 | ### 2.Create main.go 36 | ```go 37 | // Copyright (c) 2021 rookie-ninja 38 | // 39 | // Use of this source code is governed by an Apache-style 40 | // license that can be found in the LICENSE file. 41 | 42 | package main 43 | 44 | import ( 45 | "context" 46 | "fmt" 47 | "github.com/gin-gonic/gin" 48 | "github.com/rookie-ninja/rk-boot/v2" 49 | "github.com/rookie-ninja/rk-gin/v2/boot" 50 | "net/http" 51 | ) 52 | 53 | // @title Swagger Example API 54 | // @version 1.0 55 | // @description This is a sample rk-demo server. 56 | // @termsOfService http://swagger.io/terms/ 57 | 58 | // @securityDefinitions.basic BasicAuth 59 | 60 | // @contact.name API Support 61 | // @contact.url http://www.swagger.io/support 62 | // @contact.email support@swagger.io 63 | 64 | // @license.name Apache 2.0 65 | // @license.url http://www.apache.org/licenses/LICENSE-2.0.html 66 | func main() { 67 | // Create a new boot instance. 68 | boot := rkboot.NewBoot() 69 | 70 | // Register handler 71 | entry := rkgin.GetGinEntry("greeter") 72 | entry.Router.GET("/v1/greeter", Greeter) 73 | 74 | // Bootstrap 75 | boot.Bootstrap(context.TODO()) 76 | 77 | boot.WaitForShutdownSig(context.TODO()) 78 | } 79 | 80 | // Greeter handler 81 | // @Summary Greeter 82 | // @Id 1 83 | // @Tags Hello 84 | // @version 1.0 85 | // @Param name query string true "name" 86 | // @produce application/json 87 | // @Success 200 {object} GreeterResponse 88 | // @Router /v1/greeter [get] 89 | func Greeter(ctx *gin.Context) { 90 | ctx.JSON(http.StatusOK, &GreeterResponse{ 91 | Message: fmt.Sprintf("Hello %s!", ctx.Query("name")), 92 | }) 93 | } 94 | 95 | type GreeterResponse struct { 96 | Message string 97 | } 98 | ``` 99 | 100 | ### 3.Start server 101 | 102 | ```go 103 | $ go run main.go 104 | ``` 105 | 106 | ### 4.Validation 107 | - Call API: 108 | 109 | ```shell script 110 | $ curl -X GET localhost:8080/v1/greeter?name=rk-dev 111 | {"Message":"Hello rk-dev!"} 112 | 113 | $ curl -X GET localhost:8080/rk/v1/ready 114 | { 115 | "ready": true 116 | } 117 | 118 | $ curl -X GET localhost:8080/rk/v1/alive 119 | { 120 | "alive": true 121 | } 122 | ``` 123 | 124 | - Swagger UI: [http://localhost:8080/sw](http://localhost:8080/sw) 125 | 126 | ![image](docs/img/simple-sw.png) 127 | 128 | - Docs UI via: [http://localhost:8080/docs](http://localhost:8080/docs) 129 | 130 | ![image](docs/img/simple-docs.png) 131 | 132 | -------------------------------------------------------------------------------- /example/database/sqlserver/main.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 rookie-ninja 2 | // 3 | // Use of this source code is governed by an Apache-style 4 | // license that can be found in the LICENSE file. 5 | package main 6 | 7 | import ( 8 | "context" 9 | "github.com/gin-gonic/gin" 10 | "github.com/rookie-ninja/rk-boot/v2" 11 | "github.com/rookie-ninja/rk-db/sqlserver" 12 | "github.com/rookie-ninja/rk-gin/v2/boot" 13 | "gorm.io/gorm" 14 | "net/http" 15 | "strconv" 16 | "time" 17 | ) 18 | 19 | var userDb *gorm.DB 20 | 21 | func main() { 22 | boot := rkboot.NewBoot() 23 | 24 | boot.Bootstrap(context.TODO()) 25 | 26 | // Auto migrate database and init global userDb variable 27 | sqlServerEntry := rksqlserver.GetSqlServerEntry("user-db") 28 | userDb = sqlServerEntry.GetDB("user") 29 | if !userDb.DryRun { 30 | userDb.AutoMigrate(&User{}) 31 | } 32 | 33 | // Register APIs 34 | ginEntry := rkgin.GetGinEntry("user-service") 35 | ginEntry.Router.GET("/v1/user", ListUsers) 36 | ginEntry.Router.GET("/v1/user/:id", GetUser) 37 | ginEntry.Router.PUT("/v1/user", CreateUser) 38 | ginEntry.Router.POST("/v1/user/:id", UpdateUser) 39 | ginEntry.Router.DELETE("/v1/user/:id", DeleteUser) 40 | 41 | boot.WaitForShutdownSig(context.TODO()) 42 | } 43 | 44 | // ************************************* 45 | // *************** Model *************** 46 | // ************************************* 47 | 48 | type Base struct { 49 | CreatedAt time.Time `yaml:"-" json:"-"` 50 | UpdatedAt time.Time `yaml:"-" json:"-"` 51 | DeletedAt gorm.DeletedAt `yaml:"-" json:"-" gorm:"index"` 52 | } 53 | 54 | type User struct { 55 | Base 56 | Id int `yaml:"id" json:"id" gorm:"primaryKey"` 57 | Name string `yaml:"name" json:"name"` 58 | } 59 | 60 | func ListUsers(ctx *gin.Context) { 61 | userList := make([]*User, 0) 62 | res := userDb.Find(&userList) 63 | 64 | if res.Error != nil { 65 | ctx.JSON(http.StatusInternalServerError, res.Error) 66 | return 67 | } 68 | ctx.JSON(http.StatusOK, userList) 69 | } 70 | 71 | func GetUser(ctx *gin.Context) { 72 | uid := ctx.Param("id") 73 | user := &User{} 74 | res := userDb.Where("id = ?", uid).Find(user) 75 | 76 | if res.Error != nil { 77 | ctx.JSON(http.StatusInternalServerError, res.Error) 78 | return 79 | } 80 | ctx.JSON(http.StatusOK, user) 81 | } 82 | 83 | func CreateUser(ctx *gin.Context) { 84 | user := &User{ 85 | Name: ctx.Query("name"), 86 | } 87 | 88 | res := userDb.Create(user) 89 | 90 | if res.Error != nil { 91 | ctx.JSON(http.StatusInternalServerError, res.Error) 92 | return 93 | } 94 | ctx.JSON(http.StatusOK, user) 95 | } 96 | 97 | func UpdateUser(ctx *gin.Context) { 98 | uid := ctx.Param("id") 99 | user := &User{ 100 | Name: ctx.Query("name"), 101 | } 102 | 103 | res := userDb.Where("id = ?", uid).Updates(user) 104 | 105 | if res.Error != nil { 106 | ctx.JSON(http.StatusInternalServerError, res.Error) 107 | return 108 | } 109 | 110 | if res.RowsAffected < 1 { 111 | ctx.JSON(http.StatusNotFound, "user not found") 112 | return 113 | } 114 | 115 | // get user 116 | userDb.Where("id = ?", uid).Find(user) 117 | 118 | ctx.JSON(http.StatusOK, user) 119 | } 120 | 121 | func DeleteUser(ctx *gin.Context) { 122 | uid, _ := strconv.Atoi(ctx.Param("id")) 123 | res := userDb.Delete(&User{ 124 | Id: uid, 125 | }) 126 | 127 | if res.Error != nil { 128 | ctx.JSON(http.StatusInternalServerError, res.Error) 129 | return 130 | } 131 | 132 | if res.RowsAffected < 1 { 133 | ctx.JSON(http.StatusNotFound, "user not found") 134 | return 135 | } 136 | 137 | ctx.String(http.StatusOK, "success") 138 | } 139 | -------------------------------------------------------------------------------- /example/web/gf/README.md: -------------------------------------------------------------------------------- 1 | # Example 2 | Middleware & bootstrapper designed for [gogf/gf](https://github.com/gogf/gf) web framework. 3 | 4 | ## Documentation 5 | - [Github](https://github.com/rookie-ninja/rk-gin) 6 | - [Official Docs]() will be updated for v2 soon 7 | 8 | ![image](docs/img/gf-arch.png) 9 | 10 | ## Installation 11 | - rk-boot: Bootstrapper base 12 | - rk-gf: Bootstrapper for [gogf/gf](https://github.com/gogf/gf) 13 | 14 | ```shell 15 | go get github.com/rookie-ninja/rk-boot/v2 16 | go get github.com/rookie-ninja/rk-gf 17 | ``` 18 | 19 | ## Quick start 20 | ### 1.Create boot.yaml 21 | ```yaml 22 | --- 23 | gf: 24 | - name: greeter # Required 25 | port: 8080 # Required 26 | enabled: true # Required 27 | commonService: 28 | enabled: true # Optional, default: false 29 | sw: 30 | enabled: true # Optional, default: false 31 | docs: 32 | enabled: true # Optional, default: false 33 | ``` 34 | 35 | ### 2.Create main.go 36 | ```go 37 | // Copyright (c) 2021 rookie-ninja 38 | // 39 | // Use of this source code is governed by an Apache-style 40 | // license that can be found in the LICENSE file. 41 | 42 | package main 43 | 44 | import ( 45 | "context" 46 | "fmt" 47 | "github.com/gogf/gf/v2/net/ghttp" 48 | "github.com/rookie-ninja/rk-boot/v2" 49 | "github.com/rookie-ninja/rk-gf/boot" 50 | "net/http" 51 | ) 52 | 53 | // @title Swagger Example API 54 | // @version 1.0 55 | // @description This is a sample rk-demo server. 56 | // @termsOfService http://swagger.io/terms/ 57 | 58 | // @securityDefinitions.basic BasicAuth 59 | 60 | // @contact.name API Support 61 | // @contact.url http://www.swagger.io/support 62 | // @contact.email support@swagger.io 63 | 64 | // @license.name Apache 2.0 65 | // @license.url http://www.apache.org/licenses/LICENSE-2.0.html 66 | func main() { 67 | // Create a new boot instance. 68 | boot := rkboot.NewBoot() 69 | 70 | // Register handler 71 | entry := rkgf.GetGfEntry("greeter") 72 | entry.Server.BindHandler("/v1/greeter", Greeter) 73 | 74 | // Bootstrap 75 | boot.Bootstrap(context.TODO()) 76 | 77 | boot.WaitForShutdownSig(context.TODO()) 78 | } 79 | 80 | // Greeter handler 81 | // @Summary Greeter service 82 | // @Id 1 83 | // @version 1.0 84 | // @produce application/json 85 | // @Param name query string true "Input name" 86 | // @Success 200 {object} GreeterResponse 87 | // @Router /v1/greeter [get] 88 | func Greeter(ctx *ghttp.Request) { 89 | ctx.Response.WriteHeader(http.StatusOK) 90 | ctx.Response.WriteJson(&GreeterResponse{ 91 | Message: fmt.Sprintf("Hello %s!", ctx.GetQuery("name").String()), 92 | }) 93 | } 94 | 95 | type GreeterResponse struct { 96 | Message string 97 | } 98 | ``` 99 | 100 | ### 3.Start server 101 | 102 | ```go 103 | $ go run main.go 104 | ``` 105 | 106 | ### 4.Validation 107 | - Call API: 108 | 109 | ```shell script 110 | $ curl -X GET localhost:8080/v1/greeter?name=rk-dev 111 | {"Message":"Hello rk-dev!"} 112 | 113 | $ curl -X GET localhost:8080/rk/v1/ready 114 | { 115 | "ready": true 116 | } 117 | 118 | $ curl -X GET localhost:8080/rk/v1/alive 119 | { 120 | "alive": true 121 | } 122 | ``` 123 | 124 | - Swagger UI: [http://localhost:8080/sw](http://localhost:8080/sw) 125 | 126 | ![image](docs/img/simple-sw.png) 127 | 128 | - Docs UI via: [http://localhost:8080/docs](http://localhost:8080/docs) 129 | 130 | ![image](docs/img/simple-docs.png) 131 | 132 | -------------------------------------------------------------------------------- /example/web/echo/README.md: -------------------------------------------------------------------------------- 1 | # Example 2 | Middleware & bootstrapper designed for [labstack/echo](https://github.com/labstack/echo) web framework. 3 | 4 | ## Documentation 5 | - [Github](https://github.com/rookie-ninja/rk-echo) 6 | - [Official Docs]() will be updated for v2 soon 7 | 8 | ![image](docs/img/echo-arch.png) 9 | 10 | ## Installation 11 | - rk-boot: Bootstrapper base 12 | - rk-echo: Bootstrapper for [labstack/echo](https://github.com/labstack/echo) 13 | 14 | ```shell 15 | go get github.com/rookie-ninja/rk-boot/v2 16 | go get github.com/rookie-ninja/rk-echo 17 | ``` 18 | 19 | ## Quick start 20 | ### 1.Create boot.yaml 21 | ```yaml 22 | --- 23 | echo: 24 | - name: greeter # Required 25 | port: 8080 # Required 26 | enabled: true # Required 27 | commonService: 28 | enabled: true # Optional, default: false 29 | sw: 30 | enabled: true # Optional, default: false 31 | docs: 32 | enabled: true # Optional, default: false 33 | ``` 34 | 35 | ### 2.Create main.go 36 | ```go 37 | // Copyright (c) 2021 rookie-ninja 38 | // 39 | // Use of this source code is governed by an Apache-style 40 | // license that can be found in the LICENSE file. 41 | package main 42 | 43 | import ( 44 | "context" 45 | _ "embed" 46 | "fmt" 47 | "github.com/labstack/echo/v4" 48 | "github.com/rookie-ninja/rk-boot/v2" 49 | "github.com/rookie-ninja/rk-echo/boot" 50 | "net/http" 51 | ) 52 | 53 | // @title Swagger Example API 54 | // @version 1.0 55 | // @description This is a sample rk-demo server. 56 | // @termsOfService http://swagger.io/terms/ 57 | 58 | // @securityDefinitions.basic BasicAuth 59 | 60 | // @contact.name API Support 61 | // @contact.url http://www.swagger.io/support 62 | // @contact.email support@swagger.io 63 | 64 | // @license.name Apache 2.0 65 | // @license.url http://www.apache.org/licenses/LICENSE-2.0.html 66 | 67 | func main() { 68 | // Create a new boot instance. 69 | boot := rkboot.NewBoot() 70 | 71 | // Register handler 72 | echoEntry := rkecho.GetEchoEntry("greeter") 73 | echoEntry.Echo.GET("/v1/greeter", Greeter) 74 | 75 | // Bootstrap 76 | boot.Bootstrap(context.TODO()) 77 | 78 | boot.WaitForShutdownSig(context.TODO()) 79 | } 80 | 81 | // Greeter handler 82 | // @Summary Greeter service 83 | // @Id 1 84 | // @version 1.0 85 | // @produce application/json 86 | // @Param name query string true "Input name" 87 | // @Success 200 {object} GreeterResponse 88 | // @Router /v1/greeter [get] 89 | func Greeter(ctx echo.Context) error { 90 | return ctx.JSON(http.StatusOK, &GreeterResponse{ 91 | Message: fmt.Sprintf("Hello %s!", ctx.QueryParam("name")), 92 | }) 93 | } 94 | 95 | type GreeterResponse struct { 96 | Message string 97 | } 98 | ``` 99 | 100 | ### 3.Start server 101 | 102 | ```go 103 | $ go run main.go 104 | ``` 105 | 106 | ### 4.Validation 107 | - Call API: 108 | 109 | ```shell script 110 | $ curl -X GET localhost:8080/v1/greeter?name=rk-dev 111 | {"Message":"Hello rk-dev!"} 112 | 113 | $ curl -X GET localhost:8080/rk/v1/ready 114 | { 115 | "ready": true 116 | } 117 | 118 | $ curl -X GET localhost:8080/rk/v1/alive 119 | { 120 | "alive": true 121 | } 122 | ``` 123 | 124 | - Swagger UI: [http://localhost:8080/sw](http://localhost:8080/sw) 125 | 126 | ![image](docs/img/simple-sw.png) 127 | 128 | - Docs UI via: [http://localhost:8080/docs](http://localhost:8080/docs) 129 | 130 | ![image](docs/img/simple-docs.png) 131 | 132 | -------------------------------------------------------------------------------- /example/web/zero/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/rookie-ninja/rk-demo 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/rookie-ninja/rk-boot/v2 v2.1.2 7 | github.com/rookie-ninja/rk-zero v1.2.17 8 | github.com/zeromicro/go-zero v1.4.2 9 | ) 10 | 11 | require ( 12 | github.com/benbjohnson/clock v1.3.0 // indirect 13 | github.com/beorn7/perks v1.0.1 // indirect 14 | github.com/cenkalti/backoff/v4 v4.2.1 // indirect 15 | github.com/cespare/xxhash/v2 v2.2.0 // indirect 16 | github.com/fatih/color v1.14.1 // indirect 17 | github.com/fsnotify/fsnotify v1.6.0 // indirect 18 | github.com/go-logr/logr v1.2.4 // indirect 19 | github.com/go-logr/stdr v1.2.2 // indirect 20 | github.com/golang-jwt/jwt/v4 v4.5.0 // indirect 21 | github.com/golang/protobuf v1.5.3 // indirect 22 | github.com/google/uuid v1.4.0 // indirect 23 | github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect 24 | github.com/hashicorp/hcl v1.0.0 // indirect 25 | github.com/magiconair/properties v1.8.7 // indirect 26 | github.com/mattn/go-colorable v0.1.13 // indirect 27 | github.com/mattn/go-isatty v0.0.17 // indirect 28 | github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect 29 | github.com/mitchellh/mapstructure v1.5.0 // indirect 30 | github.com/openzipkin/zipkin-go v0.4.2 // indirect 31 | github.com/pelletier/go-toml/v2 v2.1.0 // indirect 32 | github.com/prometheus/client_golang v1.17.0 // indirect 33 | github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect 34 | github.com/prometheus/common v0.44.0 // indirect 35 | github.com/prometheus/procfs v0.11.1 // indirect 36 | github.com/rookie-ninja/rk-entry/v2 v2.2.20 // indirect 37 | github.com/rookie-ninja/rk-logger v1.2.13 // indirect 38 | github.com/rookie-ninja/rk-query v1.2.14 // indirect 39 | github.com/spaolacci/murmur3 v1.1.0 // indirect 40 | github.com/spf13/afero v1.10.0 // indirect 41 | github.com/spf13/cast v1.5.1 // indirect 42 | github.com/spf13/jwalterweatherman v1.1.0 // indirect 43 | github.com/spf13/pflag v1.0.5 // indirect 44 | github.com/spf13/viper v1.17.0 // indirect 45 | github.com/streadway/handy v0.0.0-20200128134331-0f66f006fb2e // indirect 46 | github.com/subosito/gotenv v1.6.0 // indirect 47 | go.opentelemetry.io/contrib v1.19.0 // indirect 48 | go.opentelemetry.io/otel v1.18.0 // indirect 49 | go.opentelemetry.io/otel/exporters/jaeger v1.11.0 // indirect 50 | go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.18.0 // indirect 51 | go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.18.0 // indirect 52 | go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.18.0 // indirect 53 | go.opentelemetry.io/otel/exporters/zipkin v1.18.0 // indirect 54 | go.opentelemetry.io/otel/metric v1.18.0 // indirect 55 | go.opentelemetry.io/otel/sdk v1.18.0 // indirect 56 | go.opentelemetry.io/otel/trace v1.18.0 // indirect 57 | go.opentelemetry.io/proto/otlp v1.0.0 // indirect 58 | go.uber.org/atomic v1.11.0 // indirect 59 | go.uber.org/automaxprocs v1.5.1 // indirect 60 | go.uber.org/multierr v1.10.0 // indirect 61 | go.uber.org/ratelimit v0.3.0 // indirect 62 | go.uber.org/zap v1.25.0 // indirect 63 | golang.org/x/net v0.15.0 // indirect 64 | golang.org/x/sys v0.12.0 // indirect 65 | golang.org/x/text v0.13.0 // indirect 66 | google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb // indirect 67 | google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect 68 | google.golang.org/grpc v1.58.2 // indirect 69 | google.golang.org/protobuf v1.31.0 // indirect 70 | gopkg.in/ini.v1 v1.67.0 // indirect 71 | gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect 72 | gopkg.in/yaml.v2 v2.4.0 // indirect 73 | gopkg.in/yaml.v3 v3.0.1 // indirect 74 | ) 75 | 76 | replace github.com/rookie-ninja/rk-boot/v2 => ../../../ 77 | -------------------------------------------------------------------------------- /example/web/grpc/api/gen/v1/greeter_grpc.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go-grpc. DO NOT EDIT. 2 | 3 | package greeter 4 | 5 | import ( 6 | context "context" 7 | grpc "google.golang.org/grpc" 8 | codes "google.golang.org/grpc/codes" 9 | status "google.golang.org/grpc/status" 10 | ) 11 | 12 | // This is a compile-time assertion to ensure that this generated file 13 | // is compatible with the grpc package it is being compiled against. 14 | // Requires gRPC-Go v1.32.0 or later. 15 | const _ = grpc.SupportPackageIsVersion7 16 | 17 | // GreeterClient is the client API for Greeter service. 18 | // 19 | // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. 20 | type GreeterClient interface { 21 | Hello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloResponse, error) 22 | } 23 | 24 | type greeterClient struct { 25 | cc grpc.ClientConnInterface 26 | } 27 | 28 | func NewGreeterClient(cc grpc.ClientConnInterface) GreeterClient { 29 | return &greeterClient{cc} 30 | } 31 | 32 | func (c *greeterClient) Hello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloResponse, error) { 33 | out := new(HelloResponse) 34 | err := c.cc.Invoke(ctx, "/api.v1.Greeter/Hello", in, out, opts...) 35 | if err != nil { 36 | return nil, err 37 | } 38 | return out, nil 39 | } 40 | 41 | // GreeterServer is the server API for Greeter service. 42 | // All implementations should embed UnimplementedGreeterServer 43 | // for forward compatibility 44 | type GreeterServer interface { 45 | Hello(context.Context, *HelloRequest) (*HelloResponse, error) 46 | } 47 | 48 | // UnimplementedGreeterServer should be embedded to have forward compatible implementations. 49 | type UnimplementedGreeterServer struct { 50 | } 51 | 52 | func (UnimplementedGreeterServer) Hello(context.Context, *HelloRequest) (*HelloResponse, error) { 53 | return nil, status.Errorf(codes.Unimplemented, "method Hello not implemented") 54 | } 55 | 56 | // UnsafeGreeterServer may be embedded to opt out of forward compatibility for this service. 57 | // Use of this interface is not recommended, as added methods to GreeterServer will 58 | // result in compilation errors. 59 | type UnsafeGreeterServer interface { 60 | mustEmbedUnimplementedGreeterServer() 61 | } 62 | 63 | func RegisterGreeterServer(s grpc.ServiceRegistrar, srv GreeterServer) { 64 | s.RegisterService(&Greeter_ServiceDesc, srv) 65 | } 66 | 67 | func _Greeter_Hello_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 68 | in := new(HelloRequest) 69 | if err := dec(in); err != nil { 70 | return nil, err 71 | } 72 | if interceptor == nil { 73 | return srv.(GreeterServer).Hello(ctx, in) 74 | } 75 | info := &grpc.UnaryServerInfo{ 76 | Server: srv, 77 | FullMethod: "/api.v1.Greeter/Hello", 78 | } 79 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 80 | return srv.(GreeterServer).Hello(ctx, req.(*HelloRequest)) 81 | } 82 | return interceptor(ctx, in, info, handler) 83 | } 84 | 85 | // Greeter_ServiceDesc is the grpc.ServiceDesc for Greeter service. 86 | // It's only intended for direct use with grpc.RegisterService, 87 | // and not to be introspected or modified (even as a copy) 88 | var Greeter_ServiceDesc = grpc.ServiceDesc{ 89 | ServiceName: "api.v1.Greeter", 90 | HandlerType: (*GreeterServer)(nil), 91 | Methods: []grpc.MethodDesc{ 92 | { 93 | MethodName: "Hello", 94 | Handler: _Greeter_Hello_Handler, 95 | }, 96 | }, 97 | Streams: []grpc.StreamDesc{}, 98 | Metadata: "v1/greeter.proto", 99 | } 100 | -------------------------------------------------------------------------------- /example/web/zero/README.md: -------------------------------------------------------------------------------- 1 | # Example 2 | Middleware & bootstrapper designed for [zeromicro/go-zero](https://github.com/zeromicro/go-zero) web framework. 3 | 4 | ## Documentation 5 | - [Github](https://github.com/rookie-ninja/rk-zero) 6 | - [Official Docs]() will be updated for v2 soon 7 | 8 | ![image](docs/img/zero-arch.png) 9 | 10 | ## Installation 11 | - rk-boot: Bootstrapper base 12 | - rk-zero: Bootstrapper for [zeromicro/go-zero](https://github.com/zeromicro/go-zero) 13 | 14 | ```shell 15 | go get github.com/rookie-ninja/rk-boot/v2 16 | go get github.com/rookie-ninja/rk-zero 17 | ``` 18 | 19 | ## Quick start 20 | ### 1.Create boot.yaml 21 | ```yaml 22 | --- 23 | zero: 24 | - name: greeter # Required 25 | port: 8080 # Required 26 | enabled: true # Required 27 | commonService: 28 | enabled: true # Optional, default: false 29 | sw: 30 | enabled: true # Optional, default: false 31 | docs: 32 | enabled: true # Optional, default: false 33 | ``` 34 | 35 | ### 2.Create main.go 36 | ```go 37 | package main 38 | 39 | import ( 40 | "context" 41 | "encoding/json" 42 | "fmt" 43 | "github.com/rookie-ninja/rk-boot/v2" 44 | "github.com/rookie-ninja/rk-zero/boot" 45 | "github.com/zeromicro/go-zero/rest" 46 | "net/http" 47 | ) 48 | 49 | // @title Swagger Example API 50 | // @version 1.0 51 | // @description This is a sample rk-demo server. 52 | // @termsOfService http://swagger.io/terms/ 53 | 54 | // @securityDefinitions.basic BasicAuth 55 | 56 | // @contact.name API Support 57 | // @contact.url http://www.swagger.io/support 58 | // @contact.email support@swagger.io 59 | 60 | // @license.name Apache 2.0 61 | // @license.url http://www.apache.org/licenses/LICENSE-2.0.html 62 | 63 | func main() { 64 | // Create a new boot instance. 65 | boot := rkboot.NewBoot() 66 | 67 | // Register handler 68 | zeroEntry := rkzero.GetZeroEntry("greeter") 69 | zeroEntry.Server.AddRoute(rest.Route{ 70 | Method: http.MethodGet, 71 | Path: "/v1/greeter", 72 | Handler: Greeter, 73 | }) 74 | 75 | // Bootstrap 76 | boot.Bootstrap(context.TODO()) 77 | 78 | boot.WaitForShutdownSig(context.TODO()) 79 | } 80 | 81 | // Greeter handler 82 | // @Summary Greeter 83 | // @Id 1 84 | // @Tags Hello 85 | // @version 1.0 86 | // @Param name query string true "name" 87 | // @produce application/json 88 | // @Success 200 {object} GreeterResponse 89 | // @Router /v1/greeter [get] 90 | func Greeter(writer http.ResponseWriter, request *http.Request) { 91 | writer.WriteHeader(http.StatusOK) 92 | resp := &GreeterResponse{ 93 | Message: fmt.Sprintf("Hello %s!", request.URL.Query().Get("name")), 94 | } 95 | bytes, _ := json.Marshal(resp) 96 | writer.Write(bytes) 97 | } 98 | 99 | type GreeterResponse struct { 100 | Message string 101 | } 102 | ``` 103 | 104 | ### 3.Start server 105 | 106 | ```go 107 | $ go run main.go 108 | ``` 109 | 110 | ### 4.Validation 111 | - Call API: 112 | 113 | ```shell script 114 | $ curl -X GET localhost:8080/v1/greeter?name=rk-dev 115 | {"Message":"Hello rk-dev!"} 116 | 117 | $ curl -X GET localhost:8080/rk/v1/ready 118 | { 119 | "ready": true 120 | } 121 | 122 | $ curl -X GET localhost:8080/rk/v1/alive 123 | { 124 | "alive": true 125 | } 126 | ``` 127 | 128 | - Swagger UI: [http://localhost:8080/sw](http://localhost:8080/sw) 129 | 130 | ![image](docs/img/simple-sw.png) 131 | 132 | - Docs UI via: [http://localhost:8080/docs](http://localhost:8080/docs) 133 | 134 | ![image](docs/img/simple-docs.png) 135 | 136 | -------------------------------------------------------------------------------- /example/web/fiber/README.md: -------------------------------------------------------------------------------- 1 | # Example 2 | Middleware & bootstrapper designed for [gofiber/fiber](https://github.com/gofiber/fiber) web framework. 3 | 4 | ## Documentation 5 | - [Github](https://github.com/rookie-ninja/rk-gin) 6 | - [Official Docs]() will be updated for v2 soon 7 | 8 | ![image](docs/img/fiber-arch.png) 9 | 10 | ## Installation 11 | - rk-boot: Bootstrapper base 12 | - rk-fiber: Bootstrapper for [gofiber/fiber](https://github.com/gofiber/fiber) 13 | 14 | ```shell 15 | go get github.com/rookie-ninja/rk-boot/v2 16 | go get github.com/rookie-ninja/rk-fiber 17 | ``` 18 | 19 | ## Quick start 20 | ### 1.Create boot.yaml 21 | ```yaml 22 | --- 23 | fiber: 24 | - name: greeter # Required 25 | port: 8080 # Required 26 | enabled: true # Required 27 | commonService: 28 | enabled: true # Optional, default: false 29 | sw: 30 | enabled: true # Optional, default: false 31 | docs: 32 | enabled: true # Optional, default: false 33 | ``` 34 | 35 | ### 2.Create main.go 36 | ```go 37 | // Copyright (c) 2021 rookie-ninja 38 | // 39 | // Use of this source code is governed by an Apache-style 40 | // license that can be found in the LICENSE file. 41 | 42 | package main 43 | 44 | import ( 45 | "context" 46 | "fmt" 47 | "github.com/gofiber/fiber/v2" 48 | "github.com/rookie-ninja/rk-boot/v2" 49 | "github.com/rookie-ninja/rk-fiber/boot" 50 | "net/http" 51 | ) 52 | 53 | // @title Swagger Example API 54 | // @version 1.0 55 | // @description This is a sample rk-demo server. 56 | // @termsOfService http://swagger.io/terms/ 57 | 58 | // @securityDefinitions.basic BasicAuth 59 | 60 | // @contact.name API Support 61 | // @contact.url http://www.swagger.io/support 62 | // @contact.email support@swagger.io 63 | 64 | // @license.name Apache 2.0 65 | // @license.url http://www.apache.org/licenses/LICENSE-2.0.html 66 | func main() { 67 | // Create a new boot instance. 68 | boot := rkboot.NewBoot() 69 | 70 | // Bootstrap 71 | boot.Bootstrap(context.TODO()) 72 | 73 | // Register handler 74 | entry := rkfiber.GetFiberEntry("greeter") 75 | entry.App.Get("/v1/greeter", Greeter) 76 | // This is required!!! 77 | entry.RefreshFiberRoutes() 78 | 79 | boot.WaitForShutdownSig(context.TODO()) 80 | } 81 | 82 | // Greeter handler 83 | // @Summary Greeter 84 | // @Id 1 85 | // @Tags Hello 86 | // @version 1.0 87 | // @Param name query string true "name" 88 | // @produce application/json 89 | // @Success 200 {object} GreeterResponse 90 | // @Router /v1/greeter [get] 91 | func Greeter(ctx *fiber.Ctx) error { 92 | ctx.Response().SetStatusCode(http.StatusOK) 93 | return ctx.JSON(&GreeterResponse{ 94 | Message: fmt.Sprintf("Hello %s!", ctx.Query("name")), 95 | }) 96 | } 97 | 98 | type GreeterResponse struct { 99 | Message string 100 | } 101 | ``` 102 | 103 | ### 3.Start server 104 | 105 | ```go 106 | $ go run main.go 107 | ``` 108 | 109 | ### 4.Validation 110 | - Call API: 111 | 112 | ```shell script 113 | $ curl -X GET localhost:8080/v1/greeter?name=rk-dev 114 | {"Message":"Hello rk-dev!"} 115 | 116 | $ curl -X GET localhost:8080/rk/v1/ready 117 | { 118 | "ready": true 119 | } 120 | 121 | $ curl -X GET localhost:8080/rk/v1/alive 122 | { 123 | "alive": true 124 | } 125 | ``` 126 | 127 | - Swagger UI: [http://localhost:8080/sw](http://localhost:8080/sw) 128 | 129 | ![image](docs/img/simple-sw.png) 130 | 131 | - Docs UI via: [http://localhost:8080/docs](http://localhost:8080/docs) 132 | 133 | ![image](docs/img/simple-docs.png) 134 | 135 | -------------------------------------------------------------------------------- /example/web/echo/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/rookie-ninja/rk-demo 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/labstack/echo/v4 v4.11.2 7 | github.com/rookie-ninja/rk-boot/v2 v2.1.2 8 | github.com/rookie-ninja/rk-echo v1.2.17 9 | ) 10 | 11 | replace github.com/rookie-ninja/rk-boot/v2 => ../../../ 12 | 13 | require ( 14 | github.com/benbjohnson/clock v1.3.0 // indirect 15 | github.com/beorn7/perks v1.0.1 // indirect 16 | github.com/cenkalti/backoff/v4 v4.2.1 // indirect 17 | github.com/cespare/xxhash/v2 v2.2.0 // indirect 18 | github.com/fsnotify/fsnotify v1.6.0 // indirect 19 | github.com/go-logr/logr v1.2.4 // indirect 20 | github.com/go-logr/stdr v1.2.2 // indirect 21 | github.com/golang-jwt/jwt v3.2.2+incompatible // indirect 22 | github.com/golang-jwt/jwt/v4 v4.5.0 // indirect 23 | github.com/golang/protobuf v1.5.3 // indirect 24 | github.com/google/uuid v1.4.0 // indirect 25 | github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect 26 | github.com/hashicorp/hcl v1.0.0 // indirect 27 | github.com/labstack/gommon v0.4.0 // indirect 28 | github.com/magiconair/properties v1.8.7 // indirect 29 | github.com/mattn/go-colorable v0.1.13 // indirect 30 | github.com/mattn/go-isatty v0.0.19 // indirect 31 | github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect 32 | github.com/mitchellh/mapstructure v1.5.0 // indirect 33 | github.com/openzipkin/zipkin-go v0.4.2 // indirect 34 | github.com/pelletier/go-toml/v2 v2.1.0 // indirect 35 | github.com/prometheus/client_golang v1.17.0 // indirect 36 | github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect 37 | github.com/prometheus/common v0.44.0 // indirect 38 | github.com/prometheus/procfs v0.11.1 // indirect 39 | github.com/rookie-ninja/rk-entry/v2 v2.2.20 // indirect 40 | github.com/rookie-ninja/rk-logger v1.2.13 // indirect 41 | github.com/rookie-ninja/rk-query v1.2.14 // indirect 42 | github.com/rs/xid v1.3.0 // indirect 43 | github.com/spf13/afero v1.10.0 // indirect 44 | github.com/spf13/cast v1.5.1 // indirect 45 | github.com/spf13/jwalterweatherman v1.1.0 // indirect 46 | github.com/spf13/pflag v1.0.5 // indirect 47 | github.com/spf13/viper v1.17.0 // indirect 48 | github.com/subosito/gotenv v1.6.0 // indirect 49 | github.com/valyala/bytebufferpool v1.0.0 // indirect 50 | github.com/valyala/fasttemplate v1.2.2 // indirect 51 | go.opentelemetry.io/contrib v1.19.0 // indirect 52 | go.opentelemetry.io/otel v1.18.0 // indirect 53 | go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.18.0 // indirect 54 | go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.18.0 // indirect 55 | go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.18.0 // indirect 56 | go.opentelemetry.io/otel/exporters/zipkin v1.18.0 // indirect 57 | go.opentelemetry.io/otel/metric v1.18.0 // indirect 58 | go.opentelemetry.io/otel/sdk v1.18.0 // indirect 59 | go.opentelemetry.io/otel/trace v1.18.0 // indirect 60 | go.opentelemetry.io/proto/otlp v1.0.0 // indirect 61 | go.uber.org/atomic v1.11.0 // indirect 62 | go.uber.org/multierr v1.10.0 // indirect 63 | go.uber.org/ratelimit v0.3.0 // indirect 64 | go.uber.org/zap v1.25.0 // indirect 65 | golang.org/x/crypto v0.14.0 // indirect 66 | golang.org/x/net v0.17.0 // indirect 67 | golang.org/x/sys v0.13.0 // indirect 68 | golang.org/x/text v0.13.0 // indirect 69 | golang.org/x/time v0.3.0 // indirect 70 | google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb // indirect 71 | google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect 72 | google.golang.org/grpc v1.58.2 // indirect 73 | google.golang.org/protobuf v1.31.0 // indirect 74 | gopkg.in/ini.v1 v1.67.0 // indirect 75 | gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect 76 | gopkg.in/yaml.v2 v2.4.0 // indirect 77 | gopkg.in/yaml.v3 v3.0.1 // indirect 78 | ) 79 | -------------------------------------------------------------------------------- /example/web/fiber/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/rookie-ninja/rk-demo 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/gofiber/fiber/v2 v2.50.0 7 | github.com/rookie-ninja/rk-boot/v2 v2.1.2 8 | github.com/rookie-ninja/rk-fiber v1.2.18 9 | ) 10 | 11 | require ( 12 | github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129 // indirect 13 | github.com/andybalholm/brotli v1.0.5 // indirect 14 | github.com/beorn7/perks v1.0.1 // indirect 15 | github.com/cenkalti/backoff/v4 v4.2.1 // indirect 16 | github.com/cespare/xxhash/v2 v2.2.0 // indirect 17 | github.com/fsnotify/fsnotify v1.6.0 // indirect 18 | github.com/go-logr/logr v1.2.4 // indirect 19 | github.com/go-logr/stdr v1.2.2 // indirect 20 | github.com/gofiber/adaptor/v2 v2.1.29 // indirect 21 | github.com/golang-jwt/jwt/v4 v4.5.0 // indirect 22 | github.com/golang/protobuf v1.5.3 // indirect 23 | github.com/google/uuid v1.4.0 // indirect 24 | github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect 25 | github.com/hashicorp/hcl v1.0.0 // indirect 26 | github.com/klauspost/compress v1.17.0 // indirect 27 | github.com/magiconair/properties v1.8.7 // indirect 28 | github.com/mattn/go-colorable v0.1.13 // indirect 29 | github.com/mattn/go-isatty v0.0.19 // indirect 30 | github.com/mattn/go-runewidth v0.0.15 // indirect 31 | github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect 32 | github.com/mitchellh/mapstructure v1.5.0 // indirect 33 | github.com/openzipkin/zipkin-go v0.4.2 // indirect 34 | github.com/pelletier/go-toml v1.9.5 // indirect 35 | github.com/pelletier/go-toml/v2 v2.1.0 // indirect 36 | github.com/prometheus/client_golang v1.17.0 // indirect 37 | github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect 38 | github.com/prometheus/common v0.44.0 // indirect 39 | github.com/prometheus/procfs v0.11.1 // indirect 40 | github.com/rivo/uniseg v0.2.0 // indirect 41 | github.com/rookie-ninja/rk-entry/v2 v2.2.20 // indirect 42 | github.com/rookie-ninja/rk-logger v1.2.13 // indirect 43 | github.com/rookie-ninja/rk-query v1.2.14 // indirect 44 | github.com/spf13/afero v1.10.0 // indirect 45 | github.com/spf13/cast v1.5.1 // indirect 46 | github.com/spf13/jwalterweatherman v1.1.0 // indirect 47 | github.com/spf13/pflag v1.0.5 // indirect 48 | github.com/spf13/viper v1.17.0 // indirect 49 | github.com/stretchr/objx v0.5.0 // indirect 50 | github.com/subosito/gotenv v1.6.0 // indirect 51 | github.com/valyala/bytebufferpool v1.0.0 // indirect 52 | github.com/valyala/fasthttp v1.50.0 // indirect 53 | github.com/valyala/tcplisten v1.0.0 // indirect 54 | go.opentelemetry.io/contrib v1.19.0 // indirect 55 | go.opentelemetry.io/otel v1.18.0 // indirect 56 | go.opentelemetry.io/otel/exporters/jaeger v1.8.0 // indirect 57 | go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.10.0 // indirect 58 | go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.18.0 // indirect 59 | go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.18.0 // indirect 60 | go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.18.0 // indirect 61 | go.opentelemetry.io/otel/exporters/zipkin v1.18.0 // indirect 62 | go.opentelemetry.io/otel/sdk v1.18.0 // indirect 63 | go.opentelemetry.io/otel/trace v1.18.0 // indirect 64 | go.opentelemetry.io/proto/otlp v1.0.0 // indirect 65 | go.uber.org/atomic v1.11.0 // indirect 66 | go.uber.org/multierr v1.10.0 // indirect 67 | go.uber.org/ratelimit v0.3.0 // indirect 68 | go.uber.org/zap v1.25.0 // indirect 69 | golang.org/x/net v0.15.0 // indirect 70 | golang.org/x/sys v0.13.0 // indirect 71 | golang.org/x/text v0.13.0 // indirect 72 | google.golang.org/genproto v0.0.0-20230913181813-007df8e322eb // indirect 73 | google.golang.org/grpc v1.58.2 // indirect 74 | google.golang.org/protobuf v1.31.0 // indirect 75 | gopkg.in/ini.v1 v1.67.0 // indirect 76 | gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect 77 | gopkg.in/yaml.v2 v2.4.0 // indirect 78 | gopkg.in/yaml.v3 v3.0.1 // indirect 79 | ) 80 | 81 | replace github.com/rookie-ninja/rk-boot/v2 => ../../../ 82 | -------------------------------------------------------------------------------- /example/web/gf/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/rookie-ninja/rk-demo 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/gogf/gf/v2 v2.5.6 7 | github.com/rookie-ninja/rk-boot/v2 v2.1.2 8 | github.com/rookie-ninja/rk-gf v1.2.16 9 | ) 10 | 11 | require ( 12 | github.com/BurntSushi/toml v1.2.0 // indirect 13 | github.com/benbjohnson/clock v1.3.0 // indirect 14 | github.com/beorn7/perks v1.0.1 // indirect 15 | github.com/cenkalti/backoff/v4 v4.2.1 // indirect 16 | github.com/cespare/xxhash/v2 v2.2.0 // indirect 17 | github.com/clbanning/mxj/v2 v2.7.0 // indirect 18 | github.com/fatih/color v1.15.0 // indirect 19 | github.com/fsnotify/fsnotify v1.6.0 // indirect 20 | github.com/go-logr/logr v1.2.4 // indirect 21 | github.com/go-logr/stdr v1.2.2 // indirect 22 | github.com/golang-jwt/jwt/v4 v4.5.0 // indirect 23 | github.com/golang/protobuf v1.5.3 // indirect 24 | github.com/google/uuid v1.4.0 // indirect 25 | github.com/gorilla/websocket v1.5.0 // indirect 26 | github.com/grokify/html-strip-tags-go v0.0.1 // indirect 27 | github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect 28 | github.com/hashicorp/hcl v1.0.0 // indirect 29 | github.com/magiconair/properties v1.8.7 // indirect 30 | github.com/mattn/go-colorable v0.1.13 // indirect 31 | github.com/mattn/go-isatty v0.0.19 // indirect 32 | github.com/mattn/go-runewidth v0.0.15 // indirect 33 | github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect 34 | github.com/mitchellh/mapstructure v1.5.0 // indirect 35 | github.com/olekukonko/tablewriter v0.0.5 // indirect 36 | github.com/openzipkin/zipkin-go v0.4.2 // indirect 37 | github.com/pelletier/go-toml/v2 v2.1.0 // indirect 38 | github.com/prometheus/client_golang v1.17.0 // indirect 39 | github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect 40 | github.com/prometheus/common v0.44.0 // indirect 41 | github.com/prometheus/procfs v0.11.1 // indirect 42 | github.com/rivo/uniseg v0.4.4 // indirect 43 | github.com/rookie-ninja/rk-entry/v2 v2.2.20 // indirect 44 | github.com/rookie-ninja/rk-logger v1.2.13 // indirect 45 | github.com/rookie-ninja/rk-query v1.2.14 // indirect 46 | github.com/sagikazarmark/locafero v0.3.0 // indirect 47 | github.com/sagikazarmark/slog-shim v0.1.0 // indirect 48 | github.com/sourcegraph/conc v0.3.0 // indirect 49 | github.com/spf13/afero v1.10.0 // indirect 50 | github.com/spf13/cast v1.5.1 // indirect 51 | github.com/spf13/pflag v1.0.5 // indirect 52 | github.com/spf13/viper v1.17.0 // indirect 53 | github.com/subosito/gotenv v1.6.0 // indirect 54 | go.opentelemetry.io/contrib v1.19.0 // indirect 55 | go.opentelemetry.io/otel v1.18.0 // indirect 56 | go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.18.0 // indirect 57 | go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.18.0 // indirect 58 | go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.18.0 // indirect 59 | go.opentelemetry.io/otel/exporters/zipkin v1.18.0 // indirect 60 | go.opentelemetry.io/otel/metric v1.18.0 // indirect 61 | go.opentelemetry.io/otel/sdk v1.18.0 // indirect 62 | go.opentelemetry.io/otel/trace v1.18.0 // indirect 63 | go.opentelemetry.io/proto/otlp v1.0.0 // indirect 64 | go.uber.org/atomic v1.11.0 // indirect 65 | go.uber.org/multierr v1.10.0 // indirect 66 | go.uber.org/ratelimit v0.3.0 // indirect 67 | go.uber.org/zap v1.25.0 // indirect 68 | golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect 69 | golang.org/x/net v0.17.0 // indirect 70 | golang.org/x/sys v0.13.0 // indirect 71 | golang.org/x/text v0.13.0 // indirect 72 | google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb // indirect 73 | google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect 74 | google.golang.org/grpc v1.58.2 // indirect 75 | google.golang.org/protobuf v1.31.0 // indirect 76 | gopkg.in/ini.v1 v1.67.0 // indirect 77 | gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect 78 | gopkg.in/yaml.v2 v2.4.0 // indirect 79 | gopkg.in/yaml.v3 v3.0.1 // indirect 80 | ) 81 | 82 | replace github.com/rookie-ninja/rk-boot/v2 => ../../../ 83 | -------------------------------------------------------------------------------- /example/middleware/jwt/gin/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/rookie-ninja/rk-demo 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/gin-gonic/gin v1.8.1 7 | github.com/golang-jwt/jwt/v4 v4.5.0 8 | github.com/rookie-ninja/rk-boot/v2 v2.1.2 9 | github.com/rookie-ninja/rk-entry/v2 v2.2.20 10 | github.com/rookie-ninja/rk-gin/v2 v2.2.16 11 | ) 12 | 13 | require ( 14 | github.com/benbjohnson/clock v1.3.0 // indirect 15 | github.com/beorn7/perks v1.0.1 // indirect 16 | github.com/cenkalti/backoff/v4 v4.2.1 // indirect 17 | github.com/cespare/xxhash/v2 v2.2.0 // indirect 18 | github.com/fsnotify/fsnotify v1.6.0 // indirect 19 | github.com/gin-contrib/pprof v1.4.0 // indirect 20 | github.com/gin-contrib/sse v0.1.0 // indirect 21 | github.com/go-logr/logr v1.2.4 // indirect 22 | github.com/go-logr/stdr v1.2.2 // indirect 23 | github.com/go-playground/locales v0.14.0 // indirect 24 | github.com/go-playground/universal-translator v0.18.0 // indirect 25 | github.com/go-playground/validator/v10 v10.10.0 // indirect 26 | github.com/goccy/go-json v0.9.7 // indirect 27 | github.com/golang/protobuf v1.5.3 // indirect 28 | github.com/google/uuid v1.4.0 // indirect 29 | github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect 30 | github.com/hashicorp/hcl v1.0.0 // indirect 31 | github.com/json-iterator/go v1.1.12 // indirect 32 | github.com/leodido/go-urn v1.2.1 // indirect 33 | github.com/magiconair/properties v1.8.7 // indirect 34 | github.com/mattn/go-isatty v0.0.17 // indirect 35 | github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect 36 | github.com/mitchellh/mapstructure v1.5.0 // indirect 37 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 38 | github.com/modern-go/reflect2 v1.0.2 // indirect 39 | github.com/openzipkin/zipkin-go v0.4.2 // indirect 40 | github.com/pelletier/go-toml/v2 v2.1.0 // indirect 41 | github.com/prometheus/client_golang v1.17.0 // indirect 42 | github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect 43 | github.com/prometheus/common v0.44.0 // indirect 44 | github.com/prometheus/procfs v0.11.1 // indirect 45 | github.com/rookie-ninja/rk-logger v1.2.13 // indirect 46 | github.com/rookie-ninja/rk-query v1.2.14 // indirect 47 | github.com/rs/xid v1.3.0 // indirect 48 | github.com/spf13/afero v1.10.0 // indirect 49 | github.com/spf13/cast v1.5.1 // indirect 50 | github.com/spf13/jwalterweatherman v1.1.0 // indirect 51 | github.com/spf13/pflag v1.0.5 // indirect 52 | github.com/spf13/viper v1.17.0 // indirect 53 | github.com/subosito/gotenv v1.6.0 // indirect 54 | github.com/ugorji/go/codec v1.2.7 // indirect 55 | go.opentelemetry.io/contrib v1.19.0 // indirect 56 | go.opentelemetry.io/otel v1.18.0 // indirect 57 | go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.18.0 // indirect 58 | go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.18.0 // indirect 59 | go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.18.0 // indirect 60 | go.opentelemetry.io/otel/exporters/zipkin v1.18.0 // indirect 61 | go.opentelemetry.io/otel/metric v1.18.0 // indirect 62 | go.opentelemetry.io/otel/sdk v1.18.0 // indirect 63 | go.opentelemetry.io/otel/trace v1.18.0 // indirect 64 | go.opentelemetry.io/proto/otlp v1.0.0 // indirect 65 | go.uber.org/atomic v1.11.0 // indirect 66 | go.uber.org/multierr v1.10.0 // indirect 67 | go.uber.org/ratelimit v0.3.0 // indirect 68 | go.uber.org/zap v1.25.0 // indirect 69 | golang.org/x/crypto v0.13.0 // indirect 70 | golang.org/x/net v0.15.0 // indirect 71 | golang.org/x/sys v0.12.0 // indirect 72 | golang.org/x/text v0.13.0 // indirect 73 | google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb // indirect 74 | google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect 75 | google.golang.org/grpc v1.58.2 // indirect 76 | google.golang.org/protobuf v1.31.0 // indirect 77 | gopkg.in/ini.v1 v1.67.0 // indirect 78 | gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect 79 | gopkg.in/yaml.v2 v2.4.0 // indirect 80 | gopkg.in/yaml.v3 v3.0.1 // indirect 81 | ) 82 | 83 | replace github.com/rookie-ninja/rk-boot/v2 => ../../../../ 84 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | **Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)* 4 | 5 | - [Contributor Covenant Code of Conduct](#contributor-covenant-code-of-conduct) 6 | - [Our Pledge](#our-pledge) 7 | - [Our Standards](#our-standards) 8 | - [Our Responsibilities](#our-responsibilities) 9 | - [Scope](#scope) 10 | - [Enforcement](#enforcement) 11 | - [Attribution](#attribution) 12 | 13 | 14 | 15 | # Contributor Covenant Code of Conduct 16 | 17 | ## Our Pledge 18 | 19 | In the interest of fostering an open and welcoming environment, we as 20 | contributors and maintainers pledge to making participation in our project and 21 | our community a harassment-free experience for everyone, regardless of age, 22 | body size, disability, ethnicity, gender identity and expression, level of 23 | experience, nationality, personal appearance, race, religion, or sexual 24 | identity and orientation. 25 | 26 | ## Our Standards 27 | 28 | Examples of behavior that contributes to creating a positive environment 29 | include: 30 | 31 | * Using welcoming and inclusive language 32 | * Being respectful of differing viewpoints and experiences 33 | * Gracefully accepting constructive criticism 34 | * Focusing on what is best for the community 35 | * Showing empathy towards other community members 36 | 37 | Examples of unacceptable behavior by participants include: 38 | 39 | * The use of sexualized language or imagery and unwelcome sexual attention or 40 | advances 41 | * Trolling, insulting/derogatory comments, and personal or political attacks 42 | * Public or private harassment 43 | * Publishing others' private information, such as a physical or electronic 44 | address, without explicit permission 45 | * Other conduct which could reasonably be considered inappropriate in a 46 | professional setting 47 | 48 | ## Our Responsibilities 49 | 50 | Project maintainers are responsible for clarifying the standards of acceptable 51 | behavior and are expected to take appropriate and fair corrective action in 52 | response to any instances of unacceptable behavior. 53 | 54 | Project maintainers have the right and responsibility to remove, edit, or 55 | reject comments, commits, code, wiki edits, issues, and other contributions 56 | that are not aligned to this Code of Conduct, or to ban temporarily or 57 | permanently any contributor for other behaviors that they deem inappropriate, 58 | threatening, offensive, or harmful. 59 | 60 | ## Scope 61 | 62 | This Code of Conduct applies both within project spaces and in public spaces 63 | when an individual is representing the project or its community. Examples of 64 | representing a project or community include using an official project e-mail 65 | address, posting via an official social media account, or acting as an 66 | appointed representative at an online or offline event. Representation of a 67 | project may be further defined and clarified by project maintainers. 68 | 69 | ## Enforcement 70 | 71 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 72 | reported by contacting the project team at lark@rkdev.info. The project 73 | team will review and investigate all complaints, and will respond in a way 74 | that it deems appropriate to the circumstances. The project team is obligated 75 | to maintain confidentiality with regard to the reporter of an incident. 76 | Further details of specific enforcement policies may be posted separately. 77 | 78 | Project maintainers who do not follow or enforce the Code of Conduct in good 79 | faith may face temporary or permanent repercussions as determined by other 80 | members of the project's leadership. 81 | 82 | ## Attribution 83 | 84 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 85 | version 1.4, available at 86 | [http://contributor-covenant.org/version/1/4][version]. 87 | 88 | [homepage]: http://contributor-covenant.org 89 | [version]: http://contributor-covenant.org/version/1/4/ -------------------------------------------------------------------------------- /example/database/mongodb/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "encoding/json" 6 | "fmt" 7 | "github.com/gin-gonic/gin" 8 | "github.com/rookie-ninja/rk-boot/v2" 9 | "github.com/rookie-ninja/rk-db/mongodb" 10 | "github.com/rookie-ninja/rk-gin/v2/boot" 11 | "github.com/rs/xid" 12 | "go.mongodb.org/mongo-driver/bson" 13 | "go.mongodb.org/mongo-driver/mongo" 14 | "go.mongodb.org/mongo-driver/mongo/options" 15 | "net/http" 16 | ) 17 | 18 | var ( 19 | userCollection *mongo.Collection 20 | ) 21 | 22 | func createCollection(db *mongo.Database, name string) { 23 | opts := options.CreateCollection() 24 | err := db.CreateCollection(context.TODO(), name, opts) 25 | if err != nil { 26 | fmt.Println("collection exists may be, continue") 27 | } 28 | } 29 | 30 | func main() { 31 | boot := rkboot.NewBoot() 32 | 33 | boot.Bootstrap(context.TODO()) 34 | 35 | // Auto migrate database and init global userDb variable 36 | db := rkmongo.GetMongoDB("my-mongo", "users") 37 | createCollection(db, "meta") 38 | 39 | userCollection = db.Collection("meta") 40 | 41 | // Register APIs 42 | ginEntry := rkgin.GetGinEntry("user-service") 43 | ginEntry.Router.GET("/v1/user", ListUsers) 44 | ginEntry.Router.GET("/v1/user/:id", GetUser) 45 | ginEntry.Router.PUT("/v1/user", CreateUser) 46 | ginEntry.Router.POST("/v1/user/:id", UpdateUser) 47 | ginEntry.Router.DELETE("/v1/user/:id", DeleteUser) 48 | 49 | boot.WaitForShutdownSig(context.TODO()) 50 | } 51 | 52 | // ************************************* 53 | // *************** Model *************** 54 | // ************************************* 55 | 56 | type User struct { 57 | Id string `bson:"id" yaml:"id" json:"id"` 58 | Name string `bson:"name" yaml:"name" json:"name"` 59 | } 60 | 61 | func ListUsers(ctx *gin.Context) { 62 | userList := make([]*User, 0) 63 | 64 | cursor, err := userCollection.Find(context.Background(), bson.D{}) 65 | 66 | if err != nil { 67 | ctx.JSON(http.StatusInternalServerError, err) 68 | return 69 | } 70 | 71 | if err = cursor.All(context.TODO(), &userList); err != nil { 72 | ctx.JSON(http.StatusInternalServerError, err) 73 | return 74 | } 75 | 76 | ctx.JSON(http.StatusOK, userList) 77 | } 78 | 79 | func GetUser(ctx *gin.Context) { 80 | res := userCollection.FindOne(context.Background(), bson.M{"id": ctx.Param("id")}) 81 | 82 | if res.Err() != nil { 83 | ctx.AbortWithError(http.StatusInternalServerError, res.Err()) 84 | return 85 | } 86 | 87 | user := &User{} 88 | err := res.Decode(user) 89 | if err != nil { 90 | ctx.AbortWithError(http.StatusInternalServerError, err) 91 | return 92 | } 93 | 94 | ctx.JSON(http.StatusOK, user) 95 | } 96 | 97 | func CreateUser(ctx *gin.Context) { 98 | user := &User{ 99 | Id: xid.New().String(), 100 | Name: ctx.Query("name"), 101 | } 102 | 103 | _, err := userCollection.InsertOne(context.Background(), user) 104 | 105 | if err != nil { 106 | ctx.JSON(http.StatusInternalServerError, err) 107 | return 108 | } 109 | 110 | ctx.JSON(http.StatusOK, user) 111 | } 112 | 113 | func UpdateUser(ctx *gin.Context) { 114 | uid := ctx.Param("id") 115 | 116 | user := &User{ 117 | Id: uid, 118 | Name: ctx.Query("name"), 119 | } 120 | 121 | res, err := userCollection.UpdateOne(context.Background(), bson.M{"id": uid}, bson.D{ 122 | {"$set", user}, 123 | }) 124 | 125 | if err != nil { 126 | ctx.AbortWithError(http.StatusInternalServerError, err) 127 | return 128 | } 129 | 130 | if res.MatchedCount < 1 { 131 | ctx.JSON(http.StatusNotFound, "user not found") 132 | return 133 | } 134 | 135 | bytes, _ := json.Marshal(user) 136 | fmt.Println(string(bytes)) 137 | 138 | ctx.JSON(http.StatusOK, user) 139 | } 140 | 141 | func DeleteUser(ctx *gin.Context) { 142 | res, err := userCollection.DeleteOne(context.Background(), bson.M{ 143 | "id": ctx.Param("id"), 144 | }) 145 | 146 | if err != nil { 147 | ctx.AbortWithError(http.StatusInternalServerError, err) 148 | return 149 | } 150 | 151 | if res.DeletedCount < 1 { 152 | ctx.JSON(http.StatusNotFound, "user not found") 153 | return 154 | } 155 | 156 | ctx.String(http.StatusOK, "success") 157 | } 158 | -------------------------------------------------------------------------------- /example/database/mysql/main.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 rookie-ninja 2 | // 3 | // Use of this source code is governed by an Apache-style 4 | // license that can be found in the LICENSE file. 5 | package main 6 | 7 | import ( 8 | "context" 9 | "github.com/gin-gonic/gin" 10 | "github.com/rookie-ninja/rk-boot/v2" 11 | "github.com/rookie-ninja/rk-db/mysql" 12 | "github.com/rookie-ninja/rk-gin/v2/boot" 13 | rkginctx "github.com/rookie-ninja/rk-gin/v2/middleware/context" 14 | "gorm.io/gorm" 15 | "net/http" 16 | "strconv" 17 | "time" 18 | ) 19 | 20 | var model interface{} 21 | 22 | var userDb *gorm.DB 23 | 24 | func main() { 25 | boot := rkboot.NewBoot() 26 | 27 | boot.Bootstrap(context.TODO()) 28 | 29 | // Auto migrate database and init global userDb variable 30 | mysqlEntry := rkmysql.GetMySqlEntry("user-db") 31 | userDb = mysqlEntry.GetDB("demo") 32 | model = User{} 33 | 34 | if !userDb.DryRun { 35 | userDb.AutoMigrate(&User{}) 36 | } 37 | 38 | db, _ := userDb.DB() 39 | res, _ := db.Query("SHOW TABLES") 40 | 41 | var table string 42 | 43 | for res.Next() { 44 | res.Scan(&table) 45 | } 46 | 47 | // Register APIs 48 | ginEntry := rkgin.GetGinEntry("user-service") 49 | ginEntry.Router.GET("/v1/user", ListUsers) 50 | ginEntry.Router.GET("/v1/user/:id", GetUser) 51 | ginEntry.Router.PUT("/v1/user", CreateUser) 52 | ginEntry.Router.POST("/v1/user/:id", UpdateUser) 53 | ginEntry.Router.DELETE("/v1/user/:id", DeleteUser) 54 | 55 | boot.WaitForShutdownSig(context.TODO()) 56 | } 57 | 58 | // ************************************* 59 | // *************** Model *************** 60 | // ************************************* 61 | 62 | type Base struct { 63 | CreatedAt time.Time `yaml:"-" json:"-"` 64 | UpdatedAt time.Time `yaml:"-" json:"-"` 65 | DeletedAt gorm.DeletedAt `yaml:"-" json:"-" gorm:"index"` 66 | } 67 | 68 | type User struct { 69 | Base 70 | Id int `yaml:"id" json:"id" gorm:"primaryKey"` 71 | Name string `yaml:"name" json:"name"` 72 | } 73 | 74 | func ListUsers(ctx *gin.Context) { 75 | userList := make([]User, 0) 76 | 77 | // inject logger with requestId and traceId 78 | res := userDb.WithContext(rkginctx.GormCtx(ctx)).Find(&userList) 79 | 80 | if res.Error != nil { 81 | ctx.JSON(http.StatusInternalServerError, res.Error) 82 | return 83 | } 84 | ctx.JSON(http.StatusOK, userList) 85 | } 86 | 87 | func GetUser(ctx *gin.Context) { 88 | uid := ctx.Param("id") 89 | user := &User{} 90 | res := userDb.WithContext(rkginctx.GormCtx(ctx)).Where("id = ?", uid).Find(user) 91 | 92 | if res.Error != nil { 93 | ctx.JSON(http.StatusInternalServerError, res.Error) 94 | return 95 | } 96 | 97 | if res.RowsAffected < 1 { 98 | ctx.JSON(http.StatusNotFound, "user not found") 99 | return 100 | } 101 | 102 | ctx.JSON(http.StatusOK, user) 103 | } 104 | 105 | func CreateUser(ctx *gin.Context) { 106 | user := &User{ 107 | Name: ctx.Query("name"), 108 | } 109 | 110 | res := userDb.WithContext(rkginctx.GormCtx(ctx)).Create(user) 111 | 112 | if res.Error != nil { 113 | ctx.JSON(http.StatusInternalServerError, res.Error) 114 | return 115 | } 116 | ctx.JSON(http.StatusOK, user) 117 | } 118 | 119 | func UpdateUser(ctx *gin.Context) { 120 | uid := ctx.Param("id") 121 | user := &User{ 122 | Name: ctx.Query("name"), 123 | } 124 | 125 | res := userDb.WithContext(rkginctx.GormCtx(ctx)).Where("id = ?", uid).Updates(user) 126 | 127 | if res.Error != nil { 128 | ctx.JSON(http.StatusInternalServerError, res.Error) 129 | return 130 | } 131 | 132 | if res.RowsAffected < 1 { 133 | ctx.JSON(http.StatusNotFound, "user not found") 134 | return 135 | } 136 | 137 | // get user 138 | userDb.Where("id = ?", uid).Find(user) 139 | 140 | ctx.JSON(http.StatusOK, user) 141 | } 142 | 143 | func DeleteUser(ctx *gin.Context) { 144 | uid, _ := strconv.Atoi(ctx.Param("id")) 145 | res := userDb.WithContext(rkginctx.GormCtx(ctx)).Delete(&User{ 146 | Id: uid, 147 | }) 148 | 149 | if res.Error != nil { 150 | ctx.JSON(http.StatusInternalServerError, res.Error) 151 | return 152 | } 153 | 154 | if res.RowsAffected < 1 { 155 | ctx.JSON(http.StatusNotFound, "user not found") 156 | return 157 | } 158 | 159 | ctx.String(http.StatusOK, "success") 160 | } 161 | -------------------------------------------------------------------------------- /example/database/redis/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/rookie-ninja/rk-demo 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/gin-gonic/gin v1.8.1 7 | github.com/go-redis/redis/v8 v8.11.5 8 | github.com/rookie-ninja/rk-boot/v2 v2.2.6 9 | github.com/rookie-ninja/rk-db/redis v1.2.12 10 | github.com/rookie-ninja/rk-gin/v2 v2.2.16 11 | ) 12 | 13 | require ( 14 | github.com/benbjohnson/clock v1.3.0 // indirect 15 | github.com/beorn7/perks v1.0.1 // indirect 16 | github.com/cenkalti/backoff/v4 v4.2.1 // indirect 17 | github.com/cespare/xxhash/v2 v2.2.0 // indirect 18 | github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect 19 | github.com/fsnotify/fsnotify v1.6.0 // indirect 20 | github.com/gin-contrib/pprof v1.4.0 // indirect 21 | github.com/gin-contrib/sse v0.1.0 // indirect 22 | github.com/go-logr/logr v1.2.4 // indirect 23 | github.com/go-logr/stdr v1.2.2 // indirect 24 | github.com/go-playground/locales v0.14.0 // indirect 25 | github.com/go-playground/universal-translator v0.18.0 // indirect 26 | github.com/go-playground/validator/v10 v10.10.0 // indirect 27 | github.com/go-redis/redis/extra/rediscmd/v8 v8.11.5 // indirect 28 | github.com/goccy/go-json v0.9.7 // indirect 29 | github.com/golang-jwt/jwt/v4 v4.5.0 // indirect 30 | github.com/golang/protobuf v1.5.3 // indirect 31 | github.com/google/uuid v1.4.0 // indirect 32 | github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect 33 | github.com/hashicorp/hcl v1.0.0 // indirect 34 | github.com/json-iterator/go v1.1.12 // indirect 35 | github.com/leodido/go-urn v1.2.1 // indirect 36 | github.com/magiconair/properties v1.8.7 // indirect 37 | github.com/mattn/go-isatty v0.0.17 // indirect 38 | github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect 39 | github.com/mitchellh/mapstructure v1.5.0 // indirect 40 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 41 | github.com/modern-go/reflect2 v1.0.2 // indirect 42 | github.com/openzipkin/zipkin-go v0.4.2 // indirect 43 | github.com/pelletier/go-toml/v2 v2.1.0 // indirect 44 | github.com/prometheus/client_golang v1.17.0 // indirect 45 | github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect 46 | github.com/prometheus/common v0.44.0 // indirect 47 | github.com/prometheus/procfs v0.11.1 // indirect 48 | github.com/rookie-ninja/rk-entry/v2 v2.2.20 // indirect 49 | github.com/rookie-ninja/rk-logger v1.2.13 // indirect 50 | github.com/rookie-ninja/rk-query v1.2.14 // indirect 51 | github.com/rs/xid v1.3.0 // indirect 52 | github.com/spf13/afero v1.10.0 // indirect 53 | github.com/spf13/cast v1.5.1 // indirect 54 | github.com/spf13/jwalterweatherman v1.1.0 // indirect 55 | github.com/spf13/pflag v1.0.5 // indirect 56 | github.com/spf13/viper v1.17.0 // indirect 57 | github.com/subosito/gotenv v1.6.0 // indirect 58 | github.com/ugorji/go/codec v1.2.7 // indirect 59 | go.opentelemetry.io/contrib v1.19.0 // indirect 60 | go.opentelemetry.io/otel v1.18.0 // indirect 61 | go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.18.0 // indirect 62 | go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.18.0 // indirect 63 | go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.18.0 // indirect 64 | go.opentelemetry.io/otel/exporters/zipkin v1.18.0 // indirect 65 | go.opentelemetry.io/otel/metric v1.18.0 // indirect 66 | go.opentelemetry.io/otel/sdk v1.18.0 // indirect 67 | go.opentelemetry.io/otel/trace v1.18.0 // indirect 68 | go.opentelemetry.io/proto/otlp v1.0.0 // indirect 69 | go.uber.org/atomic v1.11.0 // indirect 70 | go.uber.org/multierr v1.10.0 // indirect 71 | go.uber.org/ratelimit v0.3.0 // indirect 72 | go.uber.org/zap v1.25.0 // indirect 73 | golang.org/x/crypto v0.13.0 // indirect 74 | golang.org/x/net v0.15.0 // indirect 75 | golang.org/x/sys v0.12.0 // indirect 76 | golang.org/x/text v0.13.0 // indirect 77 | google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb // indirect 78 | google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect 79 | google.golang.org/grpc v1.58.2 // indirect 80 | google.golang.org/protobuf v1.31.0 // indirect 81 | gopkg.in/ini.v1 v1.67.0 // indirect 82 | gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect 83 | gopkg.in/yaml.v2 v2.4.0 // indirect 84 | gopkg.in/yaml.v3 v3.0.1 // indirect 85 | ) 86 | 87 | replace github.com/rookie-ninja/rk-boot/v2 => ../../../ 88 | -------------------------------------------------------------------------------- /example/database/mysql/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/rookie-ninja/rk-demo 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/gin-gonic/gin v1.8.1 7 | github.com/rookie-ninja/rk-boot/v2 v2.2.6 8 | github.com/rookie-ninja/rk-db/mysql v1.2.14 9 | github.com/rookie-ninja/rk-gin/v2 v2.2.16 10 | gorm.io/gorm v1.24.0 11 | ) 12 | 13 | require ( 14 | github.com/benbjohnson/clock v1.3.0 // indirect 15 | github.com/beorn7/perks v1.0.1 // indirect 16 | github.com/cenkalti/backoff/v4 v4.2.1 // indirect 17 | github.com/cespare/xxhash/v2 v2.2.0 // indirect 18 | github.com/fsnotify/fsnotify v1.6.0 // indirect 19 | github.com/gin-contrib/pprof v1.4.0 // indirect 20 | github.com/gin-contrib/sse v0.1.0 // indirect 21 | github.com/go-logr/logr v1.2.4 // indirect 22 | github.com/go-logr/stdr v1.2.2 // indirect 23 | github.com/go-playground/locales v0.14.0 // indirect 24 | github.com/go-playground/universal-translator v0.18.0 // indirect 25 | github.com/go-playground/validator/v10 v10.10.0 // indirect 26 | github.com/go-sql-driver/mysql v1.6.0 // indirect 27 | github.com/goccy/go-json v0.9.7 // indirect 28 | github.com/golang-jwt/jwt/v4 v4.5.0 // indirect 29 | github.com/golang/protobuf v1.5.3 // indirect 30 | github.com/google/uuid v1.4.0 // indirect 31 | github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect 32 | github.com/hashicorp/hcl v1.0.0 // indirect 33 | github.com/jinzhu/inflection v1.0.0 // indirect 34 | github.com/jinzhu/now v1.1.5 // indirect 35 | github.com/json-iterator/go v1.1.12 // indirect 36 | github.com/leodido/go-urn v1.2.1 // indirect 37 | github.com/magiconair/properties v1.8.7 // indirect 38 | github.com/mattn/go-isatty v0.0.17 // indirect 39 | github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect 40 | github.com/mitchellh/mapstructure v1.5.0 // indirect 41 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 42 | github.com/modern-go/reflect2 v1.0.2 // indirect 43 | github.com/openzipkin/zipkin-go v0.4.2 // indirect 44 | github.com/pelletier/go-toml/v2 v2.1.0 // indirect 45 | github.com/prometheus/client_golang v1.17.0 // indirect 46 | github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect 47 | github.com/prometheus/common v0.44.0 // indirect 48 | github.com/prometheus/procfs v0.11.1 // indirect 49 | github.com/rookie-ninja/rk-entry/v2 v2.2.20 // indirect 50 | github.com/rookie-ninja/rk-logger v1.2.13 // indirect 51 | github.com/rookie-ninja/rk-query v1.2.14 // indirect 52 | github.com/rs/xid v1.3.0 // indirect 53 | github.com/spf13/afero v1.10.0 // indirect 54 | github.com/spf13/cast v1.5.1 // indirect 55 | github.com/spf13/jwalterweatherman v1.1.0 // indirect 56 | github.com/spf13/pflag v1.0.5 // indirect 57 | github.com/spf13/viper v1.17.0 // indirect 58 | github.com/subosito/gotenv v1.6.0 // indirect 59 | github.com/ugorji/go/codec v1.2.7 // indirect 60 | go.opentelemetry.io/contrib v1.19.0 // indirect 61 | go.opentelemetry.io/otel v1.18.0 // indirect 62 | go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.18.0 // indirect 63 | go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.18.0 // indirect 64 | go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.18.0 // indirect 65 | go.opentelemetry.io/otel/exporters/zipkin v1.18.0 // indirect 66 | go.opentelemetry.io/otel/metric v1.18.0 // indirect 67 | go.opentelemetry.io/otel/sdk v1.18.0 // indirect 68 | go.opentelemetry.io/otel/trace v1.18.0 // indirect 69 | go.opentelemetry.io/proto/otlp v1.0.0 // indirect 70 | go.uber.org/atomic v1.11.0 // indirect 71 | go.uber.org/multierr v1.10.0 // indirect 72 | go.uber.org/ratelimit v0.3.0 // indirect 73 | go.uber.org/zap v1.25.0 // indirect 74 | golang.org/x/crypto v0.13.0 // indirect 75 | golang.org/x/net v0.15.0 // indirect 76 | golang.org/x/sys v0.12.0 // indirect 77 | golang.org/x/text v0.13.0 // indirect 78 | google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb // indirect 79 | google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect 80 | google.golang.org/grpc v1.58.2 // indirect 81 | google.golang.org/protobuf v1.31.0 // indirect 82 | gopkg.in/ini.v1 v1.67.0 // indirect 83 | gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect 84 | gopkg.in/yaml.v2 v2.4.0 // indirect 85 | gopkg.in/yaml.v3 v3.0.1 // indirect 86 | gorm.io/driver/mysql v1.4.3 // indirect 87 | ) 88 | 89 | replace github.com/rookie-ninja/rk-boot/v2 => ../../../ 90 | -------------------------------------------------------------------------------- /example/database/sqlite/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/rookie-ninja/rk-demo 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/gin-gonic/gin v1.8.1 7 | github.com/rookie-ninja/rk-boot/v2 v2.2.6 8 | github.com/rookie-ninja/rk-db/sqlite v1.2.14 9 | github.com/rookie-ninja/rk-gin/v2 v2.2.16 10 | gorm.io/gorm v1.24.0 11 | ) 12 | 13 | require ( 14 | github.com/benbjohnson/clock v1.3.0 // indirect 15 | github.com/beorn7/perks v1.0.1 // indirect 16 | github.com/cenkalti/backoff/v4 v4.2.1 // indirect 17 | github.com/cespare/xxhash/v2 v2.2.0 // indirect 18 | github.com/fsnotify/fsnotify v1.6.0 // indirect 19 | github.com/gin-contrib/pprof v1.4.0 // indirect 20 | github.com/gin-contrib/sse v0.1.0 // indirect 21 | github.com/go-logr/logr v1.2.4 // indirect 22 | github.com/go-logr/stdr v1.2.2 // indirect 23 | github.com/go-playground/locales v0.14.0 // indirect 24 | github.com/go-playground/universal-translator v0.18.0 // indirect 25 | github.com/go-playground/validator/v10 v10.10.0 // indirect 26 | github.com/goccy/go-json v0.9.7 // indirect 27 | github.com/golang-jwt/jwt/v4 v4.5.0 // indirect 28 | github.com/golang/protobuf v1.5.3 // indirect 29 | github.com/google/uuid v1.4.0 // indirect 30 | github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect 31 | github.com/hashicorp/hcl v1.0.0 // indirect 32 | github.com/jinzhu/inflection v1.0.0 // indirect 33 | github.com/jinzhu/now v1.1.5 // indirect 34 | github.com/json-iterator/go v1.1.12 // indirect 35 | github.com/leodido/go-urn v1.2.1 // indirect 36 | github.com/magiconair/properties v1.8.7 // indirect 37 | github.com/mattn/go-isatty v0.0.17 // indirect 38 | github.com/mattn/go-sqlite3 v1.14.15 // indirect 39 | github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect 40 | github.com/mitchellh/mapstructure v1.5.0 // indirect 41 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 42 | github.com/modern-go/reflect2 v1.0.2 // indirect 43 | github.com/openzipkin/zipkin-go v0.4.2 // indirect 44 | github.com/pelletier/go-toml/v2 v2.1.0 // indirect 45 | github.com/prometheus/client_golang v1.17.0 // indirect 46 | github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect 47 | github.com/prometheus/common v0.44.0 // indirect 48 | github.com/prometheus/procfs v0.11.1 // indirect 49 | github.com/rookie-ninja/rk-entry/v2 v2.2.20 // indirect 50 | github.com/rookie-ninja/rk-logger v1.2.13 // indirect 51 | github.com/rookie-ninja/rk-query v1.2.14 // indirect 52 | github.com/rs/xid v1.3.0 // indirect 53 | github.com/spf13/afero v1.10.0 // indirect 54 | github.com/spf13/cast v1.5.1 // indirect 55 | github.com/spf13/jwalterweatherman v1.1.0 // indirect 56 | github.com/spf13/pflag v1.0.5 // indirect 57 | github.com/spf13/viper v1.17.0 // indirect 58 | github.com/subosito/gotenv v1.6.0 // indirect 59 | github.com/ugorji/go/codec v1.2.7 // indirect 60 | go.opentelemetry.io/contrib v1.19.0 // indirect 61 | go.opentelemetry.io/otel v1.18.0 // indirect 62 | go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.18.0 // indirect 63 | go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.18.0 // indirect 64 | go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.18.0 // indirect 65 | go.opentelemetry.io/otel/exporters/zipkin v1.18.0 // indirect 66 | go.opentelemetry.io/otel/metric v1.18.0 // indirect 67 | go.opentelemetry.io/otel/sdk v1.18.0 // indirect 68 | go.opentelemetry.io/otel/trace v1.18.0 // indirect 69 | go.opentelemetry.io/proto/otlp v1.0.0 // indirect 70 | go.uber.org/atomic v1.11.0 // indirect 71 | go.uber.org/multierr v1.10.0 // indirect 72 | go.uber.org/ratelimit v0.3.0 // indirect 73 | go.uber.org/zap v1.25.0 // indirect 74 | golang.org/x/crypto v0.13.0 // indirect 75 | golang.org/x/net v0.15.0 // indirect 76 | golang.org/x/sys v0.12.0 // indirect 77 | golang.org/x/text v0.13.0 // indirect 78 | google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb // indirect 79 | google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect 80 | google.golang.org/grpc v1.58.2 // indirect 81 | google.golang.org/protobuf v1.31.0 // indirect 82 | gopkg.in/ini.v1 v1.67.0 // indirect 83 | gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect 84 | gopkg.in/yaml.v2 v2.4.0 // indirect 85 | gopkg.in/yaml.v3 v3.0.1 // indirect 86 | gorm.io/driver/sqlite v1.4.3 // indirect 87 | ) 88 | 89 | replace github.com/rookie-ninja/rk-boot/v2 => ../../../ 90 | -------------------------------------------------------------------------------- /example/web/grpc/third-party/googleapis/google/rpc/status.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package google.rpc; 18 | 19 | import "google/protobuf/any.proto"; 20 | 21 | option go_package = "google.golang.org/genproto/googleapis/rpc/status;status"; 22 | option java_multiple_files = true; 23 | option java_outer_classname = "StatusProto"; 24 | option java_package = "com.google.rpc"; 25 | option objc_class_prefix = "RPC"; 26 | 27 | 28 | // The `Status` type defines a logical error model that is suitable for different 29 | // programming environments, including REST APIs and RPC APIs. It is used by 30 | // [gRPC](https://github.com/grpc). The error model is designed to be: 31 | // 32 | // - Simple to use and understand for most users 33 | // - Flexible enough to meet unexpected needs 34 | // 35 | // # Overview 36 | // 37 | // The `Status` message contains three pieces of data: error code, error message, 38 | // and error details. The error code should be an enum value of 39 | // [google.rpc.Code][google.rpc.Code], but it may accept additional error codes if needed. The 40 | // error message should be a developer-facing English message that helps 41 | // developers *understand* and *resolve* the error. If a localized user-facing 42 | // error message is needed, put the localized message in the error details or 43 | // localize it in the client. The optional error details may contain arbitrary 44 | // information about the error. There is a predefined set of error detail types 45 | // in the package `google.rpc` that can be used for common error conditions. 46 | // 47 | // # Language mapping 48 | // 49 | // The `Status` message is the logical representation of the error model, but it 50 | // is not necessarily the actual wire format. When the `Status` message is 51 | // exposed in different client libraries and different wire protocols, it can be 52 | // mapped differently. For example, it will likely be mapped to some exceptions 53 | // in Java, but more likely mapped to some error codes in C. 54 | // 55 | // # Other uses 56 | // 57 | // The error model and the `Status` message can be used in a variety of 58 | // environments, either with or without APIs, to provide a 59 | // consistent developer experience across different environments. 60 | // 61 | // Example uses of this error model include: 62 | // 63 | // - Partial errors. If a service needs to return partial errors to the client, 64 | // it may embed the `Status` in the normal response to indicate the partial 65 | // errors. 66 | // 67 | // - Workflow errors. A typical workflow has multiple steps. Each step may 68 | // have a `Status` message for error reporting. 69 | // 70 | // - Batch operations. If a client uses batch request and batch response, the 71 | // `Status` message should be used directly inside batch response, one for 72 | // each error sub-response. 73 | // 74 | // - Asynchronous operations. If an API call embeds asynchronous operation 75 | // results in its response, the status of those operations should be 76 | // represented directly using the `Status` message. 77 | // 78 | // - Logging. If some API errors are stored in logs, the message `Status` could 79 | // be used directly after any stripping needed for security/privacy reasons. 80 | message Status { 81 | // The status code, which should be an enum value of [google.rpc.Code][google.rpc.Code]. 82 | int32 code = 1; 83 | 84 | // A developer-facing error message, which should be in English. Any 85 | // user-facing error message should be localized and sent in the 86 | // [google.rpc.Status.details][google.rpc.Status.details] field, or localized by the client. 87 | string message = 2; 88 | 89 | // A list of messages that carry the error details. There is a common set of 90 | // message types for APIs to use. 91 | repeated google.protobuf.Any details = 3; 92 | } 93 | -------------------------------------------------------------------------------- /example/middleware/jwt/gin/README.md: -------------------------------------------------------------------------------- 1 | # Example 2 | Implementation of JWT middleware with Login logic. 3 | 4 | ## Documentation 5 | - [Github](https://github.com/rookie-ninja/rk-gin) 6 | - [Official Docs](https://docs.rkdev.info) 7 | 8 | ## Quick start 9 | ### 1.Create boot.yaml 10 | ```yaml 11 | --- 12 | gin: 13 | - name: greeter 14 | port: 8080 15 | enabled: true 16 | sw: 17 | enabled: true 18 | middleware: 19 | jwt: 20 | enabled: true 21 | ignore: 22 | - "/v1/login" 23 | - "/sw" 24 | 25 | ``` 26 | 27 | ### 2.Create main.go 28 | ```go 29 | // Copyright (c) 2021 rookie-ninja 30 | // 31 | // Use of this source code is governed by an Apache-style 32 | // license that can be found in the LICENSE file. 33 | 34 | package main 35 | 36 | import ( 37 | "context" 38 | "encoding/json" 39 | "fmt" 40 | "github.com/gin-gonic/gin" 41 | "github.com/golang-jwt/jwt/v4" 42 | "github.com/rookie-ninja/rk-boot/v2" 43 | "github.com/rookie-ninja/rk-entry/v2/entry" 44 | "github.com/rookie-ninja/rk-gin/v2/boot" 45 | "github.com/rookie-ninja/rk-gin/v2/middleware/context" 46 | "net/http" 47 | "time" 48 | ) 49 | 50 | // @title Swagger Example API 51 | // @version 1.0 52 | // @description This is a sample rk-boot server. 53 | // @termsOfService http://swagger.io/terms/ 54 | 55 | // @securityDefinitions.apikey JWT 56 | // @in header 57 | // @name Authorization 58 | 59 | // @contact.name API Support 60 | // @contact.url http://www.swagger.io/support 61 | // @contact.email support@swagger.io 62 | 63 | // @license.name Apache 2.0 64 | // @license.url http://www.apache.org/licenses/LICENSE-2.0.html 65 | func main() { 66 | // Create a new boot instance. 67 | boot := rkboot.NewBoot() 68 | 69 | // Register handler 70 | entry := rkgin.GetGinEntry("greeter") 71 | entry.Router.GET("/v1/login", Login) 72 | entry.Router.GET("/v1/whoami", WhoAmI) 73 | 74 | // Bootstrap 75 | boot.Bootstrap(context.TODO()) 76 | 77 | boot.WaitForShutdownSig(context.TODO()) 78 | } 79 | 80 | // CustomClaims defines JWT claims 81 | type CustomClaims struct { 82 | UserName string `json:"uname"` 83 | jwt.RegisteredClaims 84 | } 85 | 86 | // Login handler 87 | // @Summary Login 88 | // @Id 1 89 | // @Tags JWT 90 | // @version 1.0 91 | // @Security JWT 92 | // @Param name query string true "name" 93 | // @produce application/json 94 | // @Router /v1/login [get] 95 | func Login(ctx *gin.Context) { 96 | // Simply generate JWT token from user provided name for demo 97 | userName := ctx.Query("name") 98 | 99 | now := time.Now() 100 | claims := CustomClaims{ 101 | UserName: userName, 102 | RegisteredClaims: jwt.RegisteredClaims{ 103 | ExpiresAt: jwt.NewNumericDate(now.Add(30 * time.Minute)), 104 | IssuedAt: jwt.NewNumericDate(now), 105 | NotBefore: jwt.NewNumericDate(now), 106 | Issuer: "rk-boot", 107 | }, 108 | } 109 | 110 | // By default, JWT middleware will create a new SignerEntry with the same name of Gin Entry 111 | // default signer entry will use symmetric algorithm (HS256) with token of (rk jwt key) 112 | // refer rkmidjwt.NewOptionSet 113 | signerEntry := rkentry.GlobalAppCtx.GetSignerJwtEntry("greeter") 114 | 115 | res, _ := signerEntry.SignJwt(claims) 116 | ctx.JSON(http.StatusOK, map[string]string{ 117 | "JwtToken": res, 118 | }) 119 | } 120 | 121 | // WhoAmI handler 122 | // @Summary WhoAmI 123 | // @Id 2 124 | // @Tags JWT 125 | // @version 1.0 126 | // @Security JWT 127 | // @produce application/json 128 | // @Router /v1/whoami [get] 129 | func WhoAmI(ctx *gin.Context) { 130 | // 1: get JWT token from context which injected into context by middleware 131 | token := rkginctx.GetJwtToken(ctx) 132 | 133 | // convert claim to custom claim 134 | claims := &CustomClaims{} 135 | bytes, _ := json.Marshal(token.Claims) 136 | json.Unmarshal(bytes, claims) 137 | 138 | ctx.JSON(http.StatusOK, map[string]string{ 139 | "Message": fmt.Sprintf("Your name is %s", claims.UserName), 140 | }) 141 | } 142 | 143 | ``` 144 | 145 | ### 3.Start server 146 | 147 | ```shell 148 | go run main.go 149 | ``` 150 | 151 | ### 4.Validation 152 | - [Swagger](http://localhost:8080/sw) 153 | 154 | - Login 155 | 156 | ![](img/login.png) 157 | 158 | - Authorise JWT in Swagger 159 | 160 | Copy returned JWT token and authorise JWT 161 | 162 | ![](img/authorise.png) 163 | 164 | - Send /v1/whoami 165 | 166 | ![](img/success.png) -------------------------------------------------------------------------------- /example/database/sqlserver/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/rookie-ninja/rk-demo 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/gin-gonic/gin v1.8.1 7 | github.com/rookie-ninja/rk-boot/v2 v2.2.6 8 | github.com/rookie-ninja/rk-db/sqlserver v1.2.14 9 | github.com/rookie-ninja/rk-gin/v2 v2.2.16 10 | gorm.io/gorm v1.24.0 11 | ) 12 | 13 | require ( 14 | github.com/benbjohnson/clock v1.3.0 // indirect 15 | github.com/beorn7/perks v1.0.1 // indirect 16 | github.com/cenkalti/backoff/v4 v4.2.1 // indirect 17 | github.com/cespare/xxhash/v2 v2.2.0 // indirect 18 | github.com/fsnotify/fsnotify v1.6.0 // indirect 19 | github.com/gin-contrib/pprof v1.4.0 // indirect 20 | github.com/gin-contrib/sse v0.1.0 // indirect 21 | github.com/go-logr/logr v1.2.4 // indirect 22 | github.com/go-logr/stdr v1.2.2 // indirect 23 | github.com/go-playground/locales v0.14.0 // indirect 24 | github.com/go-playground/universal-translator v0.18.0 // indirect 25 | github.com/go-playground/validator/v10 v10.10.0 // indirect 26 | github.com/goccy/go-json v0.9.7 // indirect 27 | github.com/golang-jwt/jwt/v4 v4.5.0 // indirect 28 | github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect 29 | github.com/golang-sql/sqlexp v0.1.0 // indirect 30 | github.com/golang/protobuf v1.5.3 // indirect 31 | github.com/google/uuid v1.4.0 // indirect 32 | github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect 33 | github.com/hashicorp/hcl v1.0.0 // indirect 34 | github.com/jinzhu/inflection v1.0.0 // indirect 35 | github.com/jinzhu/now v1.1.5 // indirect 36 | github.com/json-iterator/go v1.1.12 // indirect 37 | github.com/leodido/go-urn v1.2.1 // indirect 38 | github.com/magiconair/properties v1.8.7 // indirect 39 | github.com/mattn/go-isatty v0.0.17 // indirect 40 | github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect 41 | github.com/microsoft/go-mssqldb v0.17.0 // indirect 42 | github.com/mitchellh/mapstructure v1.5.0 // indirect 43 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 44 | github.com/modern-go/reflect2 v1.0.2 // indirect 45 | github.com/openzipkin/zipkin-go v0.4.2 // indirect 46 | github.com/pelletier/go-toml/v2 v2.1.0 // indirect 47 | github.com/prometheus/client_golang v1.17.0 // indirect 48 | github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect 49 | github.com/prometheus/common v0.44.0 // indirect 50 | github.com/prometheus/procfs v0.11.1 // indirect 51 | github.com/rookie-ninja/rk-entry/v2 v2.2.20 // indirect 52 | github.com/rookie-ninja/rk-logger v1.2.13 // indirect 53 | github.com/rookie-ninja/rk-query v1.2.14 // indirect 54 | github.com/rs/xid v1.3.0 // indirect 55 | github.com/spf13/afero v1.10.0 // indirect 56 | github.com/spf13/cast v1.5.1 // indirect 57 | github.com/spf13/jwalterweatherman v1.1.0 // indirect 58 | github.com/spf13/pflag v1.0.5 // indirect 59 | github.com/spf13/viper v1.17.0 // indirect 60 | github.com/subosito/gotenv v1.6.0 // indirect 61 | github.com/ugorji/go/codec v1.2.7 // indirect 62 | go.opentelemetry.io/contrib v1.19.0 // indirect 63 | go.opentelemetry.io/otel v1.18.0 // indirect 64 | go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.18.0 // indirect 65 | go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.18.0 // indirect 66 | go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.18.0 // indirect 67 | go.opentelemetry.io/otel/exporters/zipkin v1.18.0 // indirect 68 | go.opentelemetry.io/otel/metric v1.18.0 // indirect 69 | go.opentelemetry.io/otel/sdk v1.18.0 // indirect 70 | go.opentelemetry.io/otel/trace v1.18.0 // indirect 71 | go.opentelemetry.io/proto/otlp v1.0.0 // indirect 72 | go.uber.org/atomic v1.11.0 // indirect 73 | go.uber.org/multierr v1.10.0 // indirect 74 | go.uber.org/ratelimit v0.3.0 // indirect 75 | go.uber.org/zap v1.25.0 // indirect 76 | golang.org/x/crypto v0.13.0 // indirect 77 | golang.org/x/net v0.15.0 // indirect 78 | golang.org/x/sys v0.12.0 // indirect 79 | golang.org/x/text v0.13.0 // indirect 80 | google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb // indirect 81 | google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect 82 | google.golang.org/grpc v1.58.2 // indirect 83 | google.golang.org/protobuf v1.31.0 // indirect 84 | gopkg.in/ini.v1 v1.67.0 // indirect 85 | gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect 86 | gopkg.in/yaml.v2 v2.4.0 // indirect 87 | gopkg.in/yaml.v3 v3.0.1 // indirect 88 | gorm.io/driver/sqlserver v1.4.1 // indirect 89 | ) 90 | 91 | replace github.com/rookie-ninja/rk-boot/v2 => ../../../ 92 | -------------------------------------------------------------------------------- /example/web/gin/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/rookie-ninja/rk-demo 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/gin-gonic/gin v1.9.1 7 | github.com/rookie-ninja/rk-boot/v2 v2.1.2 8 | github.com/rookie-ninja/rk-gin/v2 v2.2.21 9 | ) 10 | 11 | require ( 12 | github.com/benbjohnson/clock v1.3.0 // indirect 13 | github.com/beorn7/perks v1.0.1 // indirect 14 | github.com/bytedance/sonic v1.9.1 // indirect 15 | github.com/cenkalti/backoff/v4 v4.2.1 // indirect 16 | github.com/cespare/xxhash/v2 v2.2.0 // indirect 17 | github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect 18 | github.com/fsnotify/fsnotify v1.6.0 // indirect 19 | github.com/gabriel-vasile/mimetype v1.4.2 // indirect 20 | github.com/gin-contrib/pprof v1.4.0 // indirect 21 | github.com/gin-contrib/sse v0.1.0 // indirect 22 | github.com/go-logr/logr v1.2.4 // indirect 23 | github.com/go-logr/stdr v1.2.2 // indirect 24 | github.com/go-playground/locales v0.14.1 // indirect 25 | github.com/go-playground/universal-translator v0.18.1 // indirect 26 | github.com/go-playground/validator/v10 v10.14.0 // indirect 27 | github.com/goccy/go-json v0.10.2 // indirect 28 | github.com/golang-jwt/jwt/v4 v4.5.0 // indirect 29 | github.com/golang/protobuf v1.5.3 // indirect 30 | github.com/google/uuid v1.4.0 // indirect 31 | github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect 32 | github.com/hashicorp/hcl v1.0.0 // indirect 33 | github.com/json-iterator/go v1.1.12 // indirect 34 | github.com/klauspost/cpuid/v2 v2.2.4 // indirect 35 | github.com/leodido/go-urn v1.2.4 // indirect 36 | github.com/magiconair/properties v1.8.7 // indirect 37 | github.com/mattn/go-isatty v0.0.19 // indirect 38 | github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect 39 | github.com/mitchellh/mapstructure v1.5.0 // indirect 40 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 41 | github.com/modern-go/reflect2 v1.0.2 // indirect 42 | github.com/openzipkin/zipkin-go v0.4.2 // indirect 43 | github.com/pelletier/go-toml/v2 v2.1.0 // indirect 44 | github.com/prometheus/client_golang v1.17.0 // indirect 45 | github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect 46 | github.com/prometheus/common v0.44.0 // indirect 47 | github.com/prometheus/procfs v0.11.1 // indirect 48 | github.com/rookie-ninja/rk-entry/v2 v2.2.20 // indirect 49 | github.com/rookie-ninja/rk-logger v1.2.13 // indirect 50 | github.com/rookie-ninja/rk-query v1.2.14 // indirect 51 | github.com/rs/xid v1.3.0 // indirect 52 | github.com/sagikazarmark/locafero v0.3.0 // indirect 53 | github.com/sagikazarmark/slog-shim v0.1.0 // indirect 54 | github.com/sourcegraph/conc v0.3.0 // indirect 55 | github.com/spf13/afero v1.10.0 // indirect 56 | github.com/spf13/cast v1.5.1 // indirect 57 | github.com/spf13/pflag v1.0.5 // indirect 58 | github.com/spf13/viper v1.17.0 // indirect 59 | github.com/subosito/gotenv v1.6.0 // indirect 60 | github.com/twitchyliquid64/golang-asm v0.15.1 // indirect 61 | github.com/ugorji/go/codec v1.2.11 // indirect 62 | go.opentelemetry.io/contrib v1.19.0 // indirect 63 | go.opentelemetry.io/otel v1.18.0 // indirect 64 | go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.18.0 // indirect 65 | go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.18.0 // indirect 66 | go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.18.0 // indirect 67 | go.opentelemetry.io/otel/exporters/zipkin v1.18.0 // indirect 68 | go.opentelemetry.io/otel/metric v1.18.0 // indirect 69 | go.opentelemetry.io/otel/sdk v1.18.0 // indirect 70 | go.opentelemetry.io/otel/trace v1.18.0 // indirect 71 | go.opentelemetry.io/proto/otlp v1.0.0 // indirect 72 | go.uber.org/atomic v1.11.0 // indirect 73 | go.uber.org/multierr v1.10.0 // indirect 74 | go.uber.org/ratelimit v0.3.0 // indirect 75 | go.uber.org/zap v1.25.0 // indirect 76 | golang.org/x/arch v0.3.0 // indirect 77 | golang.org/x/crypto v0.13.0 // indirect 78 | golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect 79 | golang.org/x/net v0.15.0 // indirect 80 | golang.org/x/sys v0.12.0 // indirect 81 | golang.org/x/text v0.13.0 // indirect 82 | google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb // indirect 83 | google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect 84 | google.golang.org/grpc v1.58.2 // indirect 85 | google.golang.org/protobuf v1.31.0 // indirect 86 | gopkg.in/ini.v1 v1.67.0 // indirect 87 | gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect 88 | gopkg.in/yaml.v2 v2.4.0 // indirect 89 | gopkg.in/yaml.v3 v3.0.1 // indirect 90 | ) 91 | 92 | replace github.com/rookie-ninja/rk-boot/v2 => ../../../ 93 | -------------------------------------------------------------------------------- /example/database/mongodb/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/rookie-ninja/rk-demo 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/gin-gonic/gin v1.8.1 7 | github.com/rookie-ninja/rk-boot/v2 v2.2.6 8 | github.com/rookie-ninja/rk-db/mongodb v1.2.12 9 | github.com/rookie-ninja/rk-gin/v2 v2.2.16 10 | github.com/rs/xid v1.3.0 11 | go.mongodb.org/mongo-driver v1.10.3 12 | ) 13 | 14 | require ( 15 | github.com/benbjohnson/clock v1.3.0 // indirect 16 | github.com/beorn7/perks v1.0.1 // indirect 17 | github.com/cenkalti/backoff/v4 v4.2.1 // indirect 18 | github.com/cespare/xxhash/v2 v2.2.0 // indirect 19 | github.com/fsnotify/fsnotify v1.6.0 // indirect 20 | github.com/gin-contrib/pprof v1.4.0 // indirect 21 | github.com/gin-contrib/sse v0.1.0 // indirect 22 | github.com/go-logr/logr v1.2.4 // indirect 23 | github.com/go-logr/stdr v1.2.2 // indirect 24 | github.com/go-playground/locales v0.14.0 // indirect 25 | github.com/go-playground/universal-translator v0.18.0 // indirect 26 | github.com/go-playground/validator/v10 v10.10.0 // indirect 27 | github.com/goccy/go-json v0.9.7 // indirect 28 | github.com/golang-jwt/jwt/v4 v4.5.0 // indirect 29 | github.com/golang/protobuf v1.5.3 // indirect 30 | github.com/golang/snappy v0.0.4 // indirect 31 | github.com/google/uuid v1.4.0 // indirect 32 | github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect 33 | github.com/hashicorp/hcl v1.0.0 // indirect 34 | github.com/json-iterator/go v1.1.12 // indirect 35 | github.com/klauspost/compress v1.17.0 // indirect 36 | github.com/leodido/go-urn v1.2.1 // indirect 37 | github.com/magiconair/properties v1.8.7 // indirect 38 | github.com/mattn/go-isatty v0.0.17 // indirect 39 | github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect 40 | github.com/mitchellh/mapstructure v1.5.0 // indirect 41 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 42 | github.com/modern-go/reflect2 v1.0.2 // indirect 43 | github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect 44 | github.com/openzipkin/zipkin-go v0.4.2 // indirect 45 | github.com/pelletier/go-toml/v2 v2.1.0 // indirect 46 | github.com/pkg/errors v0.9.1 // indirect 47 | github.com/prometheus/client_golang v1.17.0 // indirect 48 | github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect 49 | github.com/prometheus/common v0.44.0 // indirect 50 | github.com/prometheus/procfs v0.11.1 // indirect 51 | github.com/rookie-ninja/rk-entry/v2 v2.2.20 // indirect 52 | github.com/rookie-ninja/rk-logger v1.2.13 // indirect 53 | github.com/rookie-ninja/rk-query v1.2.14 // indirect 54 | github.com/spf13/afero v1.10.0 // indirect 55 | github.com/spf13/cast v1.5.1 // indirect 56 | github.com/spf13/jwalterweatherman v1.1.0 // indirect 57 | github.com/spf13/pflag v1.0.5 // indirect 58 | github.com/spf13/viper v1.17.0 // indirect 59 | github.com/subosito/gotenv v1.6.0 // indirect 60 | github.com/ugorji/go/codec v1.2.7 // indirect 61 | github.com/xdg-go/pbkdf2 v1.0.0 // indirect 62 | github.com/xdg-go/scram v1.1.1 // indirect 63 | github.com/xdg-go/stringprep v1.0.3 // indirect 64 | github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect 65 | go.opentelemetry.io/contrib v1.19.0 // indirect 66 | go.opentelemetry.io/otel v1.18.0 // indirect 67 | go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.18.0 // indirect 68 | go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.18.0 // indirect 69 | go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.18.0 // indirect 70 | go.opentelemetry.io/otel/exporters/zipkin v1.18.0 // indirect 71 | go.opentelemetry.io/otel/metric v1.18.0 // indirect 72 | go.opentelemetry.io/otel/sdk v1.18.0 // indirect 73 | go.opentelemetry.io/otel/trace v1.18.0 // indirect 74 | go.opentelemetry.io/proto/otlp v1.0.0 // indirect 75 | go.uber.org/atomic v1.11.0 // indirect 76 | go.uber.org/multierr v1.10.0 // indirect 77 | go.uber.org/ratelimit v0.3.0 // indirect 78 | go.uber.org/zap v1.25.0 // indirect 79 | golang.org/x/crypto v0.13.0 // indirect 80 | golang.org/x/net v0.15.0 // indirect 81 | golang.org/x/sync v0.3.0 // indirect 82 | golang.org/x/sys v0.12.0 // indirect 83 | golang.org/x/text v0.13.0 // indirect 84 | google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb // indirect 85 | google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect 86 | google.golang.org/grpc v1.58.2 // indirect 87 | google.golang.org/protobuf v1.31.0 // indirect 88 | gopkg.in/ini.v1 v1.67.0 // indirect 89 | gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect 90 | gopkg.in/yaml.v2 v2.4.0 // indirect 91 | gopkg.in/yaml.v3 v3.0.1 // indirect 92 | ) 93 | 94 | replace github.com/rookie-ninja/rk-boot/v2 => ../../../ 95 | -------------------------------------------------------------------------------- /example/database/mongodb-todolist/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/rookie-ninja/rk-demo 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/gin-gonic/gin v1.8.1 7 | github.com/rookie-ninja/rk-boot/v2 v2.2.3 8 | github.com/rookie-ninja/rk-db/mongodb v1.2.12 9 | github.com/rookie-ninja/rk-gin/v2 v2.2.16 10 | go.mongodb.org/mongo-driver v1.10.3 11 | ) 12 | 13 | replace github.com/rookie-ninja/rk-boot/v2 => ../../../ 14 | 15 | require ( 16 | github.com/benbjohnson/clock v1.3.0 // indirect 17 | github.com/beorn7/perks v1.0.1 // indirect 18 | github.com/cenkalti/backoff/v4 v4.2.1 // indirect 19 | github.com/cespare/xxhash/v2 v2.2.0 // indirect 20 | github.com/fsnotify/fsnotify v1.6.0 // indirect 21 | github.com/gin-contrib/pprof v1.4.0 // indirect 22 | github.com/gin-contrib/sse v0.1.0 // indirect 23 | github.com/go-logr/logr v1.2.4 // indirect 24 | github.com/go-logr/stdr v1.2.2 // indirect 25 | github.com/go-playground/locales v0.14.0 // indirect 26 | github.com/go-playground/universal-translator v0.18.0 // indirect 27 | github.com/go-playground/validator/v10 v10.11.0 // indirect 28 | github.com/goccy/go-json v0.9.7 // indirect 29 | github.com/golang-jwt/jwt/v4 v4.5.0 // indirect 30 | github.com/golang/protobuf v1.5.3 // indirect 31 | github.com/golang/snappy v0.0.4 // indirect 32 | github.com/google/uuid v1.4.0 // indirect 33 | github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect 34 | github.com/hashicorp/hcl v1.0.0 // indirect 35 | github.com/json-iterator/go v1.1.12 // indirect 36 | github.com/klauspost/compress v1.17.0 // indirect 37 | github.com/leodido/go-urn v1.2.1 // indirect 38 | github.com/magiconair/properties v1.8.7 // indirect 39 | github.com/mattn/go-isatty v0.0.17 // indirect 40 | github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect 41 | github.com/mitchellh/mapstructure v1.5.0 // indirect 42 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 43 | github.com/modern-go/reflect2 v1.0.2 // indirect 44 | github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect 45 | github.com/openzipkin/zipkin-go v0.4.2 // indirect 46 | github.com/pelletier/go-toml/v2 v2.1.0 // indirect 47 | github.com/pkg/errors v0.9.1 // indirect 48 | github.com/prometheus/client_golang v1.17.0 // indirect 49 | github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect 50 | github.com/prometheus/common v0.44.0 // indirect 51 | github.com/prometheus/procfs v0.11.1 // indirect 52 | github.com/rookie-ninja/rk-entry/v2 v2.2.20 // indirect 53 | github.com/rookie-ninja/rk-logger v1.2.13 // indirect 54 | github.com/rookie-ninja/rk-query v1.2.14 // indirect 55 | github.com/rs/xid v1.4.0 // indirect 56 | github.com/spf13/afero v1.10.0 // indirect 57 | github.com/spf13/cast v1.5.1 // indirect 58 | github.com/spf13/jwalterweatherman v1.1.0 // indirect 59 | github.com/spf13/pflag v1.0.5 // indirect 60 | github.com/spf13/viper v1.17.0 // indirect 61 | github.com/subosito/gotenv v1.6.0 // indirect 62 | github.com/ugorji/go/codec v1.2.7 // indirect 63 | github.com/xdg-go/pbkdf2 v1.0.0 // indirect 64 | github.com/xdg-go/scram v1.1.1 // indirect 65 | github.com/xdg-go/stringprep v1.0.3 // indirect 66 | github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect 67 | go.opentelemetry.io/contrib v1.19.0 // indirect 68 | go.opentelemetry.io/otel v1.18.0 // indirect 69 | go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.18.0 // indirect 70 | go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.18.0 // indirect 71 | go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.18.0 // indirect 72 | go.opentelemetry.io/otel/exporters/zipkin v1.18.0 // indirect 73 | go.opentelemetry.io/otel/metric v1.18.0 // indirect 74 | go.opentelemetry.io/otel/sdk v1.18.0 // indirect 75 | go.opentelemetry.io/otel/trace v1.18.0 // indirect 76 | go.opentelemetry.io/proto/otlp v1.0.0 // indirect 77 | go.uber.org/atomic v1.11.0 // indirect 78 | go.uber.org/multierr v1.10.0 // indirect 79 | go.uber.org/ratelimit v0.3.0 // indirect 80 | go.uber.org/zap v1.25.0 // indirect 81 | golang.org/x/crypto v0.13.0 // indirect 82 | golang.org/x/net v0.15.0 // indirect 83 | golang.org/x/sync v0.3.0 // indirect 84 | golang.org/x/sys v0.12.0 // indirect 85 | golang.org/x/text v0.13.0 // indirect 86 | google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb // indirect 87 | google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect 88 | google.golang.org/grpc v1.58.2 // indirect 89 | google.golang.org/protobuf v1.31.0 // indirect 90 | gopkg.in/ini.v1 v1.67.0 // indirect 91 | gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect 92 | gopkg.in/yaml.v2 v2.4.0 // indirect 93 | gopkg.in/yaml.v3 v3.0.1 // indirect 94 | ) 95 | -------------------------------------------------------------------------------- /example/database/postgres/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/rookie-ninja/rk-demo 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/gin-gonic/gin v1.8.1 7 | github.com/rookie-ninja/rk-boot/v2 v2.2.6 8 | github.com/rookie-ninja/rk-db/postgres v1.2.14 9 | github.com/rookie-ninja/rk-gin/v2 v2.2.16 10 | gorm.io/gorm v1.24.1-0.20221019064659-5dd2bb482755 11 | ) 12 | 13 | replace github.com/rookie-ninja/rk-boot/v2 => ../../../ 14 | 15 | require ( 16 | github.com/benbjohnson/clock v1.3.0 // indirect 17 | github.com/beorn7/perks v1.0.1 // indirect 18 | github.com/cenkalti/backoff/v4 v4.2.1 // indirect 19 | github.com/cespare/xxhash/v2 v2.2.0 // indirect 20 | github.com/fsnotify/fsnotify v1.6.0 // indirect 21 | github.com/gin-contrib/pprof v1.4.0 // indirect 22 | github.com/gin-contrib/sse v0.1.0 // indirect 23 | github.com/go-logr/logr v1.2.4 // indirect 24 | github.com/go-logr/stdr v1.2.2 // indirect 25 | github.com/go-playground/locales v0.14.0 // indirect 26 | github.com/go-playground/universal-translator v0.18.0 // indirect 27 | github.com/go-playground/validator/v10 v10.10.0 // indirect 28 | github.com/goccy/go-json v0.9.7 // indirect 29 | github.com/golang-jwt/jwt/v4 v4.5.0 // indirect 30 | github.com/golang/protobuf v1.5.3 // indirect 31 | github.com/google/uuid v1.4.0 // indirect 32 | github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect 33 | github.com/hashicorp/hcl v1.0.0 // indirect 34 | github.com/jackc/chunkreader/v2 v2.0.1 // indirect 35 | github.com/jackc/pgconn v1.13.0 // indirect 36 | github.com/jackc/pgio v1.0.0 // indirect 37 | github.com/jackc/pgpassfile v1.0.0 // indirect 38 | github.com/jackc/pgproto3/v2 v2.3.1 // indirect 39 | github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect 40 | github.com/jackc/pgtype v1.12.0 // indirect 41 | github.com/jackc/pgx/v4 v4.17.2 // indirect 42 | github.com/jinzhu/inflection v1.0.0 // indirect 43 | github.com/jinzhu/now v1.1.5 // indirect 44 | github.com/json-iterator/go v1.1.12 // indirect 45 | github.com/leodido/go-urn v1.2.1 // indirect 46 | github.com/magiconair/properties v1.8.7 // indirect 47 | github.com/mattn/go-isatty v0.0.17 // indirect 48 | github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect 49 | github.com/mitchellh/mapstructure v1.5.0 // indirect 50 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 51 | github.com/modern-go/reflect2 v1.0.2 // indirect 52 | github.com/openzipkin/zipkin-go v0.4.2 // indirect 53 | github.com/pelletier/go-toml/v2 v2.1.0 // indirect 54 | github.com/prometheus/client_golang v1.17.0 // indirect 55 | github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect 56 | github.com/prometheus/common v0.44.0 // indirect 57 | github.com/prometheus/procfs v0.11.1 // indirect 58 | github.com/rookie-ninja/rk-entry/v2 v2.2.20 // indirect 59 | github.com/rookie-ninja/rk-logger v1.2.13 // indirect 60 | github.com/rookie-ninja/rk-query v1.2.14 // indirect 61 | github.com/rs/xid v1.3.0 // indirect 62 | github.com/spf13/afero v1.10.0 // indirect 63 | github.com/spf13/cast v1.5.1 // indirect 64 | github.com/spf13/jwalterweatherman v1.1.0 // indirect 65 | github.com/spf13/pflag v1.0.5 // indirect 66 | github.com/spf13/viper v1.17.0 // indirect 67 | github.com/subosito/gotenv v1.6.0 // indirect 68 | github.com/ugorji/go/codec v1.2.7 // indirect 69 | go.opentelemetry.io/contrib v1.19.0 // indirect 70 | go.opentelemetry.io/otel v1.18.0 // indirect 71 | go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.18.0 // indirect 72 | go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.18.0 // indirect 73 | go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.18.0 // indirect 74 | go.opentelemetry.io/otel/exporters/zipkin v1.18.0 // indirect 75 | go.opentelemetry.io/otel/metric v1.18.0 // indirect 76 | go.opentelemetry.io/otel/sdk v1.18.0 // indirect 77 | go.opentelemetry.io/otel/trace v1.18.0 // indirect 78 | go.opentelemetry.io/proto/otlp v1.0.0 // indirect 79 | go.uber.org/atomic v1.11.0 // indirect 80 | go.uber.org/multierr v1.10.0 // indirect 81 | go.uber.org/ratelimit v0.3.0 // indirect 82 | go.uber.org/zap v1.25.0 // indirect 83 | golang.org/x/crypto v0.13.0 // indirect 84 | golang.org/x/net v0.15.0 // indirect 85 | golang.org/x/sys v0.12.0 // indirect 86 | golang.org/x/text v0.13.0 // indirect 87 | google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb // indirect 88 | google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect 89 | google.golang.org/grpc v1.58.2 // indirect 90 | google.golang.org/protobuf v1.31.0 // indirect 91 | gopkg.in/ini.v1 v1.67.0 // indirect 92 | gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect 93 | gopkg.in/yaml.v2 v2.4.0 // indirect 94 | gopkg.in/yaml.v3 v3.0.1 // indirect 95 | gorm.io/driver/postgres v1.4.5 // indirect 96 | ) 97 | -------------------------------------------------------------------------------- /example/cache/redis/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/rookie-ninja/rk-demo 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/gin-gonic/gin v1.8.1 7 | github.com/rookie-ninja/rk-boot/v2 v2.2.6 8 | github.com/rookie-ninja/rk-cache/redis v1.2.12 9 | github.com/rookie-ninja/rk-gin/v2 v2.2.16 10 | ) 11 | 12 | require ( 13 | github.com/benbjohnson/clock v1.3.0 // indirect 14 | github.com/beorn7/perks v1.0.1 // indirect 15 | github.com/cenkalti/backoff/v4 v4.2.1 // indirect 16 | github.com/cespare/xxhash/v2 v2.2.0 // indirect 17 | github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect 18 | github.com/fsnotify/fsnotify v1.6.0 // indirect 19 | github.com/gin-contrib/pprof v1.4.0 // indirect 20 | github.com/gin-contrib/sse v0.1.0 // indirect 21 | github.com/go-logr/logr v1.2.4 // indirect 22 | github.com/go-logr/stdr v1.2.2 // indirect 23 | github.com/go-playground/locales v0.14.0 // indirect 24 | github.com/go-playground/universal-translator v0.18.0 // indirect 25 | github.com/go-playground/validator/v10 v10.10.0 // indirect 26 | github.com/go-redis/cache/v8 v8.4.3 // indirect 27 | github.com/go-redis/redis/extra/rediscmd/v8 v8.11.5 // indirect 28 | github.com/go-redis/redis/v8 v8.11.5 // indirect 29 | github.com/goccy/go-json v0.9.7 // indirect 30 | github.com/golang-jwt/jwt/v4 v4.5.0 // indirect 31 | github.com/golang/protobuf v1.5.3 // indirect 32 | github.com/google/uuid v1.4.0 // indirect 33 | github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect 34 | github.com/hashicorp/hcl v1.0.0 // indirect 35 | github.com/json-iterator/go v1.1.12 // indirect 36 | github.com/klauspost/compress v1.17.0 // indirect 37 | github.com/leodido/go-urn v1.2.1 // indirect 38 | github.com/magiconair/properties v1.8.7 // indirect 39 | github.com/mattn/go-isatty v0.0.17 // indirect 40 | github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect 41 | github.com/mitchellh/mapstructure v1.5.0 // indirect 42 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 43 | github.com/modern-go/reflect2 v1.0.2 // indirect 44 | github.com/openzipkin/zipkin-go v0.4.2 // indirect 45 | github.com/pelletier/go-toml/v2 v2.1.0 // indirect 46 | github.com/prometheus/client_golang v1.17.0 // indirect 47 | github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect 48 | github.com/prometheus/common v0.44.0 // indirect 49 | github.com/prometheus/procfs v0.11.1 // indirect 50 | github.com/rookie-ninja/rk-db/redis v1.2.12 // indirect 51 | github.com/rookie-ninja/rk-entry/v2 v2.2.20 // indirect 52 | github.com/rookie-ninja/rk-logger v1.2.13 // indirect 53 | github.com/rookie-ninja/rk-query v1.2.14 // indirect 54 | github.com/rs/xid v1.3.0 // indirect 55 | github.com/spf13/afero v1.10.0 // indirect 56 | github.com/spf13/cast v1.5.1 // indirect 57 | github.com/spf13/jwalterweatherman v1.1.0 // indirect 58 | github.com/spf13/pflag v1.0.5 // indirect 59 | github.com/spf13/viper v1.17.0 // indirect 60 | github.com/subosito/gotenv v1.6.0 // indirect 61 | github.com/ugorji/go/codec v1.2.7 // indirect 62 | github.com/vmihailenco/go-tinylfu v0.2.2 // indirect 63 | github.com/vmihailenco/msgpack/v5 v5.3.4 // indirect 64 | github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect 65 | go.opentelemetry.io/contrib v1.19.0 // indirect 66 | go.opentelemetry.io/otel v1.18.0 // indirect 67 | go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.18.0 // indirect 68 | go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.18.0 // indirect 69 | go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.18.0 // indirect 70 | go.opentelemetry.io/otel/exporters/zipkin v1.18.0 // indirect 71 | go.opentelemetry.io/otel/metric v1.18.0 // indirect 72 | go.opentelemetry.io/otel/sdk v1.18.0 // indirect 73 | go.opentelemetry.io/otel/trace v1.18.0 // indirect 74 | go.opentelemetry.io/proto/otlp v1.0.0 // indirect 75 | go.uber.org/atomic v1.11.0 // indirect 76 | go.uber.org/multierr v1.10.0 // indirect 77 | go.uber.org/ratelimit v0.3.0 // indirect 78 | go.uber.org/zap v1.25.0 // indirect 79 | golang.org/x/crypto v0.13.0 // indirect 80 | golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect 81 | golang.org/x/net v0.15.0 // indirect 82 | golang.org/x/sync v0.3.0 // indirect 83 | golang.org/x/sys v0.12.0 // indirect 84 | golang.org/x/text v0.13.0 // indirect 85 | google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb // indirect 86 | google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect 87 | google.golang.org/grpc v1.58.2 // indirect 88 | google.golang.org/protobuf v1.31.0 // indirect 89 | gopkg.in/ini.v1 v1.67.0 // indirect 90 | gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect 91 | gopkg.in/yaml.v2 v2.4.0 // indirect 92 | gopkg.in/yaml.v3 v3.0.1 // indirect 93 | ) 94 | 95 | replace github.com/rookie-ninja/rk-boot/v2 => ../../../ 96 | -------------------------------------------------------------------------------- /example/cache/redis/README.md: -------------------------------------------------------------------------------- 1 | # Example 2 | Init cache with [go-redis/cache](https://github.com/go-redis/cache/v8) or local memory cache from YAML config. 3 | 4 | This belongs to [rk-boot](https://github.com/rookie-ninja/rk-boot) family. We suggest use this lib from [rk-boot](https://github.com/rookie-ninja/rk-boot). 5 | 6 | ## Installation 7 | - rk-boot: Bootstrapper base 8 | - rk-gin: Bootstrapper for [gin-gonic/gin](https://github.com/gin-gonic/gin) Web Framework for API 9 | - rk-cache/redis: Bootstrapper for [go-redis/cache](https://github.com/go-redis/cache/v8) of cache 10 | 11 | ``` 12 | go get github.com/rookie-ninja/rk-boot/v2 13 | go get github.com/rookie-ninja/rk-gin/v2 14 | go get github.com/rookie-ninja/rk-cache/redis 15 | ``` 16 | 17 | ## Quick Start 18 | In the bellow example, we will run Redis locally and implement API of Get/Set of K/V. 19 | 20 | - GET /v1/get, get value 21 | - POST /v1/set, set value 22 | 23 | ### 1.Create boot.yaml 24 | [boot.yaml](example/boot.yaml) 25 | 26 | - Create web server with Gin framework at port 8080 27 | - Create Redis entry which connects Redis at localhost:6379 as cache 28 | 29 | ```yaml 30 | --- 31 | gin: 32 | - name: cache-service 33 | port: 8080 34 | enabled: true 35 | cache: 36 | - name: redis-cache 37 | enabled: true 38 | local: 39 | enabled: false 40 | redis: 41 | enabled: true 42 | ``` 43 | 44 | ### 2.Create main.go 45 | 46 | In the main() function, we implement bellow things. 47 | 48 | - Register APIs into Gin router. 49 | 50 | ```go 51 | package main 52 | 53 | import ( 54 | "context" 55 | "github.com/gin-gonic/gin" 56 | "github.com/rookie-ninja/rk-boot/v2" 57 | "github.com/rookie-ninja/rk-cache/redis" 58 | "github.com/rookie-ninja/rk-gin/v2/boot" 59 | "net/http" 60 | ) 61 | 62 | var cacheEntry *rkcache.CacheEntry 63 | 64 | func main() { 65 | boot := rkboot.NewBoot() 66 | 67 | boot.Bootstrap(context.TODO()) 68 | 69 | // assign cache 70 | cacheEntry = rkcache.GetCacheEntry("redis-cache") 71 | 72 | // assign router 73 | ginEntry := rkgin.GetGinEntry("cache-service") 74 | ginEntry.Router.GET("/v1/get", Get) 75 | ginEntry.Router.GET("/v1/set", Set) 76 | 77 | boot.WaitForShutdownSig(context.TODO()) 78 | } 79 | 80 | func Get(ctx *gin.Context) { 81 | val := "" 82 | resp := cacheEntry.GetFromCache(&rkcache.CacheReq{ 83 | Key: "demo-key", 84 | Value: &val, 85 | }) 86 | 87 | if resp.Error != nil || !resp.Success { 88 | ctx.JSON(http.StatusInternalServerError, resp.Error) 89 | return 90 | } 91 | 92 | ctx.JSON(http.StatusOK, map[string]string{ 93 | "value": val, 94 | }) 95 | } 96 | 97 | func Set(ctx *gin.Context) { 98 | val, ok := ctx.GetQuery("value") 99 | if !ok { 100 | ctx.JSON(http.StatusBadRequest, "No value found") 101 | } 102 | 103 | cacheEntry.AddToCache(&rkcache.CacheReq{ 104 | Key: "demo-key", 105 | Value: val, 106 | }) 107 | 108 | ctx.JSON(http.StatusOK, map[string]string{ 109 | "value": val, 110 | }) 111 | } 112 | ``` 113 | 114 | ### 3.Start server 115 | 116 | ```shell 117 | $ go run main.go 118 | 119 | 2022-03-09T00:10:50.325+0800 INFO redis/entry.go:163 Bootstrap CacheRedisEntry {"entryName": "redis-cache", "localCache": false, "redisCache": true} 120 | 2022-03-09T00:10:50.325+0800 INFO redis@v1.0.1/boot.go:253 Bootstrap redisEntry {"eventId": "2e47b54a-a46c-4c23-ae51-f105bdbc5836", "entryName": "redis-cache", "entryType": "RedisEntry", "clientType": "Single"} 121 | 2022-03-09T00:10:50.325+0800 INFO redis@v1.0.1/boot.go:261 Ping redis at [localhost:6379] 122 | 2022-03-09T00:10:50.330+0800 INFO redis@v1.0.1/boot.go:267 Ping redis at [localhost:6379] success 123 | 2022-03-09T00:10:50.330+0800 INFO boot/gin_entry.go:624 Bootstrap GinEntry {"eventId": "2e47b54a-a46c-4c23-ae51-f105bdbc5836", "entryName": "cache-service", "entryType": "GinEntry"} 124 | ------------------------------------------------------------------------ 125 | endTime=2022-03-09T00:10:50.33088+08:00 126 | startTime=2022-03-09T00:10:50.330832+08:00 127 | elapsedNano=47527 128 | timezone=CST 129 | ids={"eventId":"2e47b54a-a46c-4c23-ae51-f105bdbc5836"} 130 | app={"appName":"","appVersion":"","entryName":"cache-service","entryType":"GinEntry"} 131 | env={"arch":"amd64","az":"*","domain":"*","hostname":"lark.local","localIP":"10.8.0.2","os":"darwin","realm":"*","region":"*"} 132 | payloads={"ginPort":8080} 133 | counters={} 134 | pairs={} 135 | timing={} 136 | remoteAddr=localhost 137 | operation=Bootstrap 138 | resCode=OK 139 | eventStatus=Ended 140 | EOE 141 | ``` 142 | 143 | ### 4.Validation 144 | #### 4.1 Set value 145 | 146 | ```shell 147 | $ curl "localhost:8080/v1/set?value=my-value" 148 | {"value":"my-value"} 149 | ``` 150 | 151 | #### 4.2 Get value 152 | 153 | ```shell 154 | $ curl localhost:8080/v1/get 155 | {"value":"my-value"} 156 | ``` 157 | 158 | #### 4.3 Validate Redis 159 | The key of cache will be encoded with MD5 and value will be base64 encoded. 160 | 161 | 162 | -------------------------------------------------------------------------------- /example/database/clickhouse/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/rookie-ninja/rk-demo 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/gin-gonic/gin v1.8.1 7 | github.com/rookie-ninja/rk-boot/v2 v2.2.6 8 | github.com/rookie-ninja/rk-db/clickhouse v1.2.14 9 | github.com/rookie-ninja/rk-gin/v2 v2.2.16 10 | github.com/rs/xid v1.3.0 11 | gorm.io/gorm v1.24.0 12 | ) 13 | 14 | replace github.com/rookie-ninja/rk-boot/v2 => ../../../ 15 | 16 | require ( 17 | github.com/ClickHouse/ch-go v0.48.0 // indirect 18 | github.com/ClickHouse/clickhouse-go/v2 v2.3.0 // indirect 19 | github.com/andybalholm/brotli v1.0.4 // indirect 20 | github.com/benbjohnson/clock v1.3.0 // indirect 21 | github.com/beorn7/perks v1.0.1 // indirect 22 | github.com/cenkalti/backoff/v4 v4.2.1 // indirect 23 | github.com/cespare/xxhash/v2 v2.2.0 // indirect 24 | github.com/fsnotify/fsnotify v1.6.0 // indirect 25 | github.com/gin-contrib/pprof v1.4.0 // indirect 26 | github.com/gin-contrib/sse v0.1.0 // indirect 27 | github.com/go-faster/city v1.0.1 // indirect 28 | github.com/go-faster/errors v0.6.1 // indirect 29 | github.com/go-logr/logr v1.2.4 // indirect 30 | github.com/go-logr/stdr v1.2.2 // indirect 31 | github.com/go-playground/locales v0.14.0 // indirect 32 | github.com/go-playground/universal-translator v0.18.0 // indirect 33 | github.com/go-playground/validator/v10 v10.10.0 // indirect 34 | github.com/goccy/go-json v0.9.7 // indirect 35 | github.com/golang-jwt/jwt/v4 v4.5.0 // indirect 36 | github.com/golang/protobuf v1.5.3 // indirect 37 | github.com/google/uuid v1.4.0 // indirect 38 | github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect 39 | github.com/hashicorp/go-version v1.6.0 // indirect 40 | github.com/hashicorp/hcl v1.0.0 // indirect 41 | github.com/jinzhu/inflection v1.0.0 // indirect 42 | github.com/jinzhu/now v1.1.5 // indirect 43 | github.com/json-iterator/go v1.1.12 // indirect 44 | github.com/klauspost/compress v1.17.0 // indirect 45 | github.com/leodido/go-urn v1.2.1 // indirect 46 | github.com/magiconair/properties v1.8.7 // indirect 47 | github.com/mattn/go-isatty v0.0.17 // indirect 48 | github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect 49 | github.com/mitchellh/mapstructure v1.5.0 // indirect 50 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 51 | github.com/modern-go/reflect2 v1.0.2 // indirect 52 | github.com/openzipkin/zipkin-go v0.4.2 // indirect 53 | github.com/paulmach/orb v0.7.1 // indirect 54 | github.com/pelletier/go-toml/v2 v2.1.0 // indirect 55 | github.com/pierrec/lz4/v4 v4.1.17 // indirect 56 | github.com/pkg/errors v0.9.1 // indirect 57 | github.com/prometheus/client_golang v1.17.0 // indirect 58 | github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect 59 | github.com/prometheus/common v0.44.0 // indirect 60 | github.com/prometheus/procfs v0.11.1 // indirect 61 | github.com/rookie-ninja/rk-entry/v2 v2.2.20 // indirect 62 | github.com/rookie-ninja/rk-logger v1.2.13 // indirect 63 | github.com/rookie-ninja/rk-query v1.2.14 // indirect 64 | github.com/segmentio/asm v1.2.0 // indirect 65 | github.com/shopspring/decimal v1.3.1 // indirect 66 | github.com/spf13/afero v1.10.0 // indirect 67 | github.com/spf13/cast v1.5.1 // indirect 68 | github.com/spf13/jwalterweatherman v1.1.0 // indirect 69 | github.com/spf13/pflag v1.0.5 // indirect 70 | github.com/spf13/viper v1.17.0 // indirect 71 | github.com/subosito/gotenv v1.6.0 // indirect 72 | github.com/ugorji/go/codec v1.2.7 // indirect 73 | go.opentelemetry.io/contrib v1.19.0 // indirect 74 | go.opentelemetry.io/otel v1.18.0 // indirect 75 | go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.18.0 // indirect 76 | go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.18.0 // indirect 77 | go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.18.0 // indirect 78 | go.opentelemetry.io/otel/exporters/zipkin v1.18.0 // indirect 79 | go.opentelemetry.io/otel/metric v1.18.0 // indirect 80 | go.opentelemetry.io/otel/sdk v1.18.0 // indirect 81 | go.opentelemetry.io/otel/trace v1.18.0 // indirect 82 | go.opentelemetry.io/proto/otlp v1.0.0 // indirect 83 | go.uber.org/atomic v1.11.0 // indirect 84 | go.uber.org/multierr v1.10.0 // indirect 85 | go.uber.org/ratelimit v0.3.0 // indirect 86 | go.uber.org/zap v1.25.0 // indirect 87 | golang.org/x/crypto v0.13.0 // indirect 88 | golang.org/x/net v0.15.0 // indirect 89 | golang.org/x/sys v0.12.0 // indirect 90 | golang.org/x/text v0.13.0 // indirect 91 | google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb // indirect 92 | google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect 93 | google.golang.org/grpc v1.58.2 // indirect 94 | google.golang.org/protobuf v1.31.0 // indirect 95 | gopkg.in/ini.v1 v1.67.0 // indirect 96 | gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect 97 | gopkg.in/yaml.v2 v2.4.0 // indirect 98 | gopkg.in/yaml.v3 v3.0.1 // indirect 99 | gorm.io/driver/clickhouse v0.5.0 // indirect 100 | ) 101 | --------------------------------------------------------------------------------