Skip to content

Commit da39bcc

Browse files
committed
update code and docs
1 parent 52a7529 commit da39bcc

File tree

572 files changed

+12934
-6094
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

572 files changed

+12934
-6094
lines changed

1_web-gin-CRUD/.golangci.yml

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ run:
1212
# default value is empty list, but default dirs are skipped independently
1313
# from this option's value (see skip-dirs-use-default).
1414
skip-dirs:
15-
- pkg
1615
- docs
1716
- api
1817
# which files to skip: they will be analyzed, but issues from them
@@ -39,7 +38,7 @@ linters:
3938
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
4039
disable-all: true
4140
enable:
42-
- golint
41+
- revive
4342
- goimports
4443
- gofmt
4544
- unused
@@ -66,6 +65,59 @@ linters:
6665

6766

6867
linters-settings:
68+
revive:
69+
rules:
70+
- name: argument-limit
71+
arguments: [ 8 ]
72+
- name: atomic
73+
- name: bare-return
74+
- name: blank-imports
75+
- name: bool-literal-in-expr
76+
- name: call-to-gc
77+
- name: confusing-naming
78+
- name: confusing-results
79+
- name: constant-logical-expr
80+
- name: context-as-argument
81+
- name: context-keys-type
82+
- name: deep-exit
83+
- name: defer
84+
- name: dot-imports
85+
- name: duplicated-imports
86+
- name: early-return
87+
- name: empty-block
88+
#- name: empty-lines
89+
- name: error-naming
90+
- name: error-return
91+
- name: error-strings
92+
- name: errorf
93+
- name: function-result-limit
94+
arguments: [ 3 ]
95+
- name: identical-branches
96+
- name: if-return
97+
- name: import-shadowing
98+
- name: increment-decrement
99+
- name: indent-error-flow
100+
- name: modifies-parameter
101+
- name: modifies-value-receiver
102+
- name: package-comments
103+
- name: range
104+
- name: range-val-address
105+
- name: range-val-in-closure
106+
- name: receiver-naming
107+
- name: redefines-builtin-id
108+
- name: string-of-int
109+
- name: struct-tag
110+
- name: superfluous-else
111+
- name: time-naming
112+
- name: unconditional-recursion
113+
- name: unexported-naming
114+
- name: unnecessary-stmt
115+
- name: unreachable-code
116+
- name: unused-parameter
117+
- name: var-declaration
118+
- name: var-naming
119+
- name: waitgroup-by-value
120+
69121
dogsled:
70122
# checks assignments with too many blank identifiers; default is 2
71123
max-blank-identifiers: 2
@@ -126,10 +178,6 @@ linters-settings:
126178
# it's a comma-separated list of prefixes
127179
local-prefixes: user
128180

129-
golint:
130-
# minimal confidence for issues, default is 0.8
131-
min-confidence: 0.8
132-
133181
gomnd:
134182
settings:
135183
mnd:

1_web-gin-CRUD/Makefile

Lines changed: 53 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,7 @@ SHELL := /bin/bash
33
PROJECT_NAME := "user"
44
PKG := "$(PROJECT_NAME)"
55
PKG_LIST := $(shell go list ${PKG}/... | grep -v /vendor/ | grep -v /api/)
6-
#GO_FILES := $(shell find . -name '*.go' | grep -v /vendor/ | grep -v _test.go)
7-
8-
9-
.PHONY: install
10-
# installation of dependent tools
11-
install:
12-
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
13-
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
14-
go install github.com/envoyproxy/protoc-gen-validate@latest
15-
go install github.com/srikrsna/protoc-gen-gotag@latest
16-
go install user/cmd/protoc-gen-go-gin@latest
17-
go install user/cmd/protoc-gen-go-rpc-tmpl@latest
18-
go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@latest
19-
go install github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc@latest
20-
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
21-
go install github.com/swaggo/swag/cmd/swag@latest
22-
go install github.com/ofabry/go-callvis@latest
23-
go install golang.org/x/pkgsite/cmd/pkgsite@latest
6+
247

258

269
.PHONY: mod
@@ -60,12 +43,6 @@ cover:
6043
go tool cover -html=cover.out
6144

6245

63-
.PHONY: docs
64-
# generate swagger docs, the host address can be changed via parameters, e.g. make docs HOST=192.168.3.37
65-
docs: mod fmt
66-
@bash scripts/swag-docs.sh $(HOST)
67-
68-
6946
.PHONY: graph
7047
# generate interactive visual function dependency graphs
7148
graph:
@@ -75,10 +52,16 @@ graph:
7552
@rm -f main.go user.gv
7653

7754

55+
.PHONY: docs
56+
# generate swagger docs, only for ⓵ Web services created based on sql, the host address can be changed via parameters, e.g. make docs HOST=192.168.3.37
57+
docs: mod fmt
58+
@bash scripts/swag-docs.sh $(HOST)
59+
60+
7861
.PHONY: proto
79-
# generate *.pb.go codes from *.proto files
62+
# generate *.go and template code by proto files, if you do not refer to the proto file, the default is all the proto files in the api directory. you can specify the proto file, multiple files are separated by commas, e.g. make proto FILES=api/user/v1/user.proto. only for ⓶ Microservices created based on sql, ⓷ Web services created based on protobuf, ⓸ Microservices created based on protobuf, ⓹ GRPC gateway service created based on protobuf
8063
proto: mod fmt
81-
@bash scripts/protoc.sh
64+
@bash scripts/protoc.sh $(FILES)
8265

8366

8467
.PHONY: proto-doc
@@ -91,9 +74,7 @@ proto-doc:
9174
# build user for linux amd64 binary
9275
build:
9376
@echo "building 'user', linux binary file will output to 'cmd/user'"
94-
@cd cmd/user && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GOPROXY=https://goproxy.cn,direct go build
95-
96-
77+
@cd cmd/user && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build
9778

9879

9980

@@ -109,12 +90,30 @@ run-nohup:
10990
@bash scripts/run-nohup.sh $(CMD)
11091

11192

112-
.PHONY: docker-image
93+
.PHONY: binary-package
94+
# packaged binary files
95+
binary-package: build
96+
@bash scripts/binary-package.sh
97+
98+
99+
.PHONY: deploy-binary
100+
# deploy binary to remote linux server, e.g. make deploy-binary USER=root PWD=123456 IP=192.168.1.10
101+
deploy-binary: binary-package
102+
@expect scripts/deploy-binary.sh $(USER) $(PWD) $(IP)
103+
104+
105+
.PHONY: image-build-local
113106
# build image for local docker, tag=latest, use binary files to build
114-
docker-image: build
107+
image-build-local: build
115108
@bash scripts/image-build-local.sh
116109

117110

111+
.PHONY: deploy-docker
112+
# deploy service to local docker, if you want to update the service, run the make deploy-docker command again.
113+
deploy-docker: image-build-local
114+
@bash scripts/deploy-docker.sh
115+
116+
118117
.PHONY: image-build
119118
# build image for remote repositories, use binary files to build, e.g. make image-build REPO_HOST=addr TAG=latest
120119
image-build:
@@ -127,12 +126,6 @@ image-build2:
127126
@bash scripts/image-build2.sh $(REPO_HOST) $(TAG)
128127

129128

130-
.PHONY: image-build-rpc-test
131-
# build rpc test image for remote repositories, e.g. make image-build-rpc-test REPO_HOST=addr TAG=latest
132-
image-build-rpc-test:
133-
@bash scripts/image-rpc-test.sh $(REPO_HOST) $(TAG)
134-
135-
136129
.PHONY: image-push
137130
# push docker image to remote repositories, e.g. make image-push REPO_HOST=addr TAG=latest
138131
image-push:
@@ -145,22 +138,28 @@ deploy-k8s:
145138
@bash scripts/deploy-k8s.sh
146139

147140

148-
.PHONY: deploy-docker
149-
# deploy service to local docker, you must first run 'make docker-image' to generate a docker image, if you want to stop the server, pass the parameter stop, e.g. make deploy-docker CMD=stop
150-
deploy-docker:
151-
@bash scripts/deploy-docker.sh $(CMD)
141+
.PHONY: image-build-rpc-test
142+
# build grpc test image for remote repositories, e.g. make image-build-rpc-test REPO_HOST=addr TAG=latest
143+
image-build-rpc-test:
144+
@bash scripts/image-rpc-test.sh $(REPO_HOST) $(TAG)
152145

153146

154-
.PHONY: binary-package
155-
# packaged binary files
156-
binary-package: build
157-
@bash scripts/binary-package.sh
147+
.PHONY: patch
148+
# patch some dependent code, such as types.proto, mysql initialization code. e.g. make patch TYPE=types-pb , make patch TYPE=mysql-init
149+
patch:
150+
@bash scripts/patch.sh $(TYPE)
158151

159152

160-
.PHONY: deploy-binary
161-
# deploy binary, e.g. make deploy-binary USER=root PWD=123456 IP=192.168.1.10
162-
deploy-binary: binary-package
163-
@expect scripts/deploy-binary.sh $(USER) $(PWD) $(IP)
153+
.PHONY: copy-proto
154+
# copy proto file from the grpc server directory, multiple directories separated by commas. e.g. make copy-proto SERVER=yourServerDir
155+
copy-proto:
156+
@sponge patch copy-proto --server-dir=$(SERVER)
157+
158+
159+
.PHONY: update-config
160+
# update internal/config code base on yaml file
161+
update-config:
162+
@sponge config --server-dir=.
164163

165164

166165
.PHONY: clean
@@ -169,10 +168,10 @@ clean:
169168
@rm -vrf cmd/user/user
170169
@rm -vrf cover.out
171170
@rm -vrf main.go user.gv
172-
@rm -vrf internal/ecode/*go.gen.*
173-
@rm -vrf internal/routers/*go.gen.*
174-
@rm -vrf internal/handler/*go.gen.*
175-
@rm -vrf internal/service/*go.gen.*
171+
@rm -vrf internal/ecode/*.go.gen*
172+
@rm -vrf internal/routers/*.go.gen*
173+
@rm -vrf internal/handler/*.go.gen*
174+
@rm -vrf internal/service/*.go.gen*
176175
@rm -rf user-binary.tar.gz
177176
@echo "clean finished"
178177

@@ -184,7 +183,7 @@ help:
184183
@echo ' make [target]'
185184
@echo ''
186185
@echo 'Targets:'
187-
@awk '/^[a-zA-Z\-\_0-9]+:/ { \
186+
@awk '/^[a-zA-Z\-_0-9]+:/ { \
188187
helpMessage = match(lastLine, /^# (.*)/); \
189188
if (helpMessage) { \
190189
helpCommand = substr($$1, 0, index($$1, ":")-1); \

1_web-gin-CRUD/README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22

33
<br>
44

5+
6+
**Import [sql](https://github.com/zhufuyi/sponge_examples/blob/main/1_web-gin-CRUD/test/sql/user.sql) into mysql before you start.**
7+
8+
<br>
9+
510
### Quickly create a web project
611

7-
Enter the Sponge UI interface, click on the left menu bar 【sql】--> 【Web type】-->【Create web project】, fill in some parameters to generate the complete project code for the web service.
12+
Enter the Sponge UI interface, click on the left menu bar 【SQL】→【Create web project】, fill in some parameters to generate the complete project code for the web service.
813

914
The web service code is mainly composed of commonly used libraries such as [gin](https://github.com/gin-gonic/gin), [gorm](https://github.com/go-gorm/gorm), [go-redis](https://github.com/go-redis/redis), and also includes swagger documentation, test code, common service governance function code, build deployment scripts, etc.
1015

@@ -28,7 +33,7 @@ Open [http://localhost:8080/swagger/index.html](http://localhost:8080/swagger/in
2833

2934
### Batch add CRUD code embedded in web service
3035

31-
Enter the Sponge UI interface, click on the left menu bar 【sql】--> 【Web type】-->【Generate handler CRUD code】, select any number of tables to generate code, then move the generated CRUD code to the web service directory to complete batch addition of CURD interfaces in the web service without changing any code.
36+
Enter the Sponge UI interface, click on the left menu bar 【Public】→【Generate handler CRUD code】, select any number of tables to generate code, then move the generated CRUD code to the web service directory to complete batch addition of CURD interfaces in the web service without changing any code.
3237

3338
![web-http-handler](https://raw.githubusercontent.com/zhufuyi/sponge_examples/main/assets/en_web-http-handler.png)
3439

@@ -43,3 +48,9 @@ make run
4348
```
4449

4550
Open [http://localhost:8080/swagger/index.html](http://localhost:8080/swagger/index.html) in your browser to see the newly added CRUD interfaces.
51+
52+
<br>
53+
54+
More detailed development documentation https://go-sponge.com/web-development-mysql
55+
56+
<br>

1_web-gin-CRUD/build/README.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

1_web-gin-CRUD/cmd/user/initial/initApp.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Package initial is the package that starts the service to initialize the service, including
2+
// the initialization configuration, service configuration, connecting to the database, and
3+
// resource release needed when shutting down the service.
14
package initial
25

36
import (
@@ -29,11 +32,14 @@ func Config() {
2932
cfg := config.Get()
3033

3134
// initializing log
32-
_, _ = logger.Init(
35+
_, err := logger.Init(
3336
logger.WithLevel(cfg.Logger.Level),
3437
logger.WithFormat(cfg.Logger.Format),
3538
logger.WithSave(cfg.Logger.IsSave),
3639
)
40+
if err != nil {
41+
panic(err)
42+
}
3743

3844
// initializing database
3945
model.InitMysql()

0 commit comments

Comments
 (0)