Skip to content

Commit

Permalink
check
Browse files Browse the repository at this point in the history
  • Loading branch information
fuwensun committed Jul 4, 2020
1 parent 25be2f7 commit 7409812
Show file tree
Hide file tree
Showing 355 changed files with 467 additions and 271 deletions.
3 changes: 2 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.

1 change: 0 additions & 1 deletion build/makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

all:test compile docker push clean

test:
Expand Down
4 changes: 0 additions & 4 deletions doc/ApiDocSwagger.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@

## swaggo

https://github.com/swaggo/gin-swagger

https://github.com/swaggo/swag



## go-swagger

https://github.com/go-swagger/go-swagger
Expand All @@ -21,4 +18,3 @@ https://goswagger.io/use/spec.html

https://medium.com/@pedram.esmaeeli/generate-swagger-specification-from-go-source-code-648615f7b9d9


2 changes: 1 addition & 1 deletion doc/DevOps.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# DevOps

# DevOps
2 changes: 0 additions & 2 deletions doc/GitOps.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@


# GitOps

8 changes: 2 additions & 6 deletions doc/Protocolbuf.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
# eApi




## Protocolbuf


### Protocol Compiler

Protocol 编译器 protoc

```
# 安装
sudo apt install protobuf-compiler
Expand Down Expand Up @@ -63,7 +59,6 @@ ls $GOPATH/src/github.com/grpc/grpc-go
>https://github.com/grpc/grpc-go
https://www.grpc.io/docs/tutorials/basic/go/


### grpc-gateway

```
Expand All @@ -87,3 +82,4 @@ protoc --swagger_out=logtostderr=true:. *.proto

>https://grpc-ecosystem.github.io/grpc-gateway/
https://github.com/grpc-ecosystem/grpc-gateway  

6 changes: 2 additions & 4 deletions doc/RESTful_API.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

## HTTP response status codes

1xx - informational
Expand Down Expand Up @@ -27,7 +26,6 @@
202 表示删除请求被接受,但还没有被执行
204 表示删除请求被执行,但没有返回被删除的资源


## HTTP request methods

### POST
Expand Down Expand Up @@ -67,7 +65,6 @@ https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Status/204
>https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Status/200
https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Status/204


总结:
post - 200 201
put - 204 201
Expand Down Expand Up @@ -160,4 +157,5 @@ HTTP状态码400 Bad Request请求PUT失败,在响应正文中使用自然语
## api 风格
- fluent style 风格 api
ruby on rails 风格的 rest 路由映射
/people/{person_id}/grounps/{group_id}
/people/{person_id}/grounps/{group_id}

8 changes: 3 additions & 5 deletions doc/开发规范.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ MD 规范 https://github.com/fuwensun/Markdown
发布规划(2) https://www.zhihu.com/question/21127832
API规范 https://www.cnblogs.com/moonz-wu/p/4211626.html


## goms 项目
工程 https://github.com/fuwensun/goms/projects/1
工单 https://github.com/fuwensun/goms/issues
PR https://github.com/fuwensun/goms/pulls


## 分支规范

集成分支
Expand Down Expand Up @@ -43,7 +41,7 @@ PR https://github.com/fuwensun/goms/pulls
集成分支
- develop
总集成分支

功能分支
- feature/{$username}/{$issue_id}_{$description}
功能或者不紧急的bugfix分支
Expand All @@ -65,7 +63,6 @@ Given a version number MAJOR.MINOR.PATCH, increment the:
- PATCH version when you make backwards compatible bug fixes.
- Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.


## 发布规范

主干开发,分支发布
Expand All @@ -78,4 +75,5 @@ Given a version number MAJOR.MINOR.PATCH, increment the:

## 错误处理

- **错误信息的打印** - 一个正例 `go: module github.com/golang/mock: Get "https://goproxy.cn/github.com/golang/mock/@v/list": dial tcp 116.207.118.45:443: connect: connection refused`. 用分号(:)来分级.上层的一般不用使用否定词,特别是 error,多个 error 使得一个错误看起来像多个错误.错误源头的信息要用否定词,如 error,failed,refused 等.
- **错误信息的打印** - 一个正例 `go: module github.com/golang/mock: Get "https://goproxy.cn/github.com/golang/mock/@v/list": dial tcp 116.207.118.45:443: connect: connection refused`. 用分号(:)来分级.上层的一般不用使用否定词,特别是 error,多个 error 使得一个错误看起来像多个错误.错误源头的信息要用否定词,如 error,failed,refused 等.

3 changes: 0 additions & 3 deletions doc/设计原则.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

SOLID
- SRP 单一职责原则 Single Responsibility Principle
- OCP 开闭原则 Open Closed Principle
Expand Down Expand Up @@ -34,5 +33,3 @@ SOLID
> 历史上存在“低层模块依赖高层模块/抽象依赖具体”,为了对此进行否定,提出“依赖倒置原则”,命名为“依赖倒置原则”。
如果没有历史包袱,命名为“依赖抽象原则”似乎更能表达意思,且可以表述为:每层都依赖抽象,具体要依赖抽象。



6 changes: 2 additions & 4 deletions eApi/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# eApi



### grpc-gateway

```
Expand All @@ -26,7 +24,6 @@ protoc --swagger_out=logtostderr=true:. *.proto
>https://grpc-ecosystem.github.io/grpc-gateway/
https://github.com/grpc-ecosystem/grpc-gateway  


### swagger

```
Expand Down Expand Up @@ -104,4 +101,5 @@ curl -X GET localhost:8081/v1/users/123456
curl -X PUT -d '{"name":"xxx","sex":0,"uid":123456}' localhost:8081/v1/users
curl -X DELETE localhost:8081/v1/users/123456
```
```

1 change: 1 addition & 0 deletions eApi/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ package v1
import empty "github.com/golang/protobuf/ptypes/empty"

type Empty = empty.Empty

1 change: 1 addition & 0 deletions eApi/api/v1/api.pb.go

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

1 change: 1 addition & 0 deletions eApi/api/v1/api.pb.gw.go

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

1 change: 1 addition & 0 deletions eApi/api/v1/api.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,4 @@
}
}
}

3 changes: 2 additions & 1 deletion eApi/api/v1/api_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

swagger serve --host=0.0.0.0 --port=9000 --no-open api.swagger.json &

hostname -I
hostname -I

1 change: 1 addition & 0 deletions eApi/api/v1/pb/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ message UserT{
message UidT{
sint64 uid = 1;
}

1 change: 1 addition & 0 deletions eApi/api/v1/pb/pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
package pb

//生成的代码中 "google/api" 要用 "google.golang.org/genproto/googleapis/api/annotations" 替代

3 changes: 2 additions & 1 deletion eApi/build/dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ COPY ./build/eApi ./
COPY ./configs ./configs
RUN ["ls","-l","./eApi"]
RUN ["ls","-l","./configs/"]
CMD ["./eApi","-cfgpath=./configs"]
CMD ["./eApi","-cfgpath=./configs"]

6 changes: 0 additions & 6 deletions eApi/build/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,3 @@ push:
clean:
rm -f $(APP_NAME)







1 change: 1 addition & 0 deletions eApi/cmd/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ func parseFlag() {
log.Info().Msgf("config path: %v", cfgpath)
model.CfgPath = cfgpath
}

1 change: 1 addition & 0 deletions eApi/cmd/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ import (

//
var log = Lg

1 change: 1 addition & 0 deletions eApi/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ func main() {
}
}
}

3 changes: 2 additions & 1 deletion eApi/configs/app.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#service:
name: user
version: v0.0.0
version: v0.0.0

3 changes: 2 additions & 1 deletion eApi/configs/grpc.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#server
addr: 0.0.0.0:50051
addr: 0.0.0.0:50051

3 changes: 2 additions & 1 deletion eApi/configs/http.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#server
addr: 0.0.0.0:8080
addr: 0.0.0.0:8080

3 changes: 2 additions & 1 deletion eApi/configs/mysql.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# mysql
dsn: "utest:pwtest@tcp(127.0.0.1:3306)/test_db?timeout=1s&readTimeout=1s&writeTimeout=1s&parseTime=true&loc=Local&charset=utf8mb4,utf8"
dsn: "utest:pwtest@tcp(127.0.0.1:3306)/test_db?timeout=1s&readTimeout=1s&writeTimeout=1s&parseTime=true&loc=Local&charset=utf8mb4,utf8"

3 changes: 2 additions & 1 deletion eApi/configs/redis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# redis
pass: "pwtest"
addr: "127.0.0.1:6379"
addr: "127.0.0.1:6379"

1 change: 1 addition & 0 deletions eApi/internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,4 @@ func InitApp(cfgpath string) (*App, func(), error) {
cleandao()
}, nil
}

1 change: 1 addition & 0 deletions eApi/internal/dao/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,4 @@ func (d *dao) Ping(ctx context.Context) (err error) {
}
return d.db.PingContext(ctx)
}

1 change: 1 addition & 0 deletions eApi/internal/dao/dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,4 @@ func teardockerdown() {
fmt.Printf("Execute Shell: %s finished with output:\n%s\n", command, string(output))
cfgstub.Reset()
}

1 change: 1 addition & 0 deletions eApi/internal/dao/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ package dao
//导出文件
//导出符号给外部测试使用,如:
//type Daot = dao

1 change: 1 addition & 0 deletions eApi/internal/dao/mock/dao.mock.go

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

1 change: 1 addition & 0 deletions eApi/internal/dao/mock/mock.go
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
//go:generate mockgen -package mock -destination ./dao.mock.go github.com/fuwensun/goms/eApi/internal/dao Dao
package mock

1 change: 1 addition & 0 deletions eApi/internal/dao/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ func (d *dao) UpdatePing(c context.Context, p *Ping) error {
log.Debug().Int64("rows", num).Msg("db update user")
return nil
}

1 change: 1 addition & 0 deletions eApi/internal/dao/testdata/configs/mysql.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# mysql
dsn: "utest:pwtest@tcp(127.0.0.1:3306)/test_db?timeout=1s&readTimeout=1s&writeTimeout=1s&parseTime=true&loc=Local&charset=utf8mb4,utf8"

1 change: 1 addition & 0 deletions eApi/internal/dao/testdata/teardocker/configs/mysql.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# mysql
dsn: "utest:pwtest@tcp(127.0.0.1:23306)/test_db?timeout=1s&readTimeout=1s&writeTimeout=1s&parseTime=true&loc=Local&charset=utf8mb4,utf8"

1 change: 1 addition & 0 deletions eApi/internal/dao/testdata/teardocker/down_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ echo $PWD
#
bash $PWD/down_mysql_docker.sh
bash $PWD/down_redis_docker.sh

1 change: 1 addition & 0 deletions eApi/internal/dao/testdata/teardocker/up_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ docker ps | grep mysqltest
docker ps | grep redistest

echo -e "\n"

1 change: 1 addition & 0 deletions eApi/internal/dao/testdata/teardocker/up_mysql_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ docker run --name mysqltest \
#ps docker
docker logs mysqltest
docker ps | grep mysqltest

1 change: 1 addition & 0 deletions eApi/internal/dao/testdata/teardocker/up_redis_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ docker run --name redistest -p 26379:6379 -d redistest

#ps docker
docker ps | grep redistest

1 change: 1 addition & 0 deletions eApi/internal/dao/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,4 @@ func (d *dao) DeleteUser(c context.Context, uid int64) error {
}
return nil
}

1 change: 1 addition & 0 deletions eApi/internal/dao/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,4 @@ func TestUser(t *testing.T) {
// 清理
clean()
}

1 change: 1 addition & 0 deletions eApi/internal/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ var ErrFailedCreateData = fmt.Errorf("data:%w", ErrFailedCreate)
var ErrInternalError = errors.New("internal error")

var CfgPath = ""

1 change: 1 addition & 0 deletions eApi/internal/model/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ type Ping struct {
Type string
Count int64
}

1 change: 1 addition & 0 deletions eApi/internal/model/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,4 @@ var ErrArgError = errors.New("arg error")
var ErrUidError = fmt.Errorf("uid %w, ECODE-%d", ErrArgError, 10001)
var ErrNameError = fmt.Errorf("name %w, ECODE-%d", ErrArgError, 10002)
var ErrSexError = fmt.Errorf("sex %w, ECODE-%d", ErrArgError, 10003)

1 change: 1 addition & 0 deletions eApi/internal/model/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,3 +351,4 @@ func TestCheckName(t *testing.T) {
})
}
}

1 change: 1 addition & 0 deletions eApi/internal/pkg/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ var Lga = lg.With().Str("layer", "dao").Logger()
func init() {
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
}

1 change: 1 addition & 0 deletions eApi/internal/server/grpc/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ func newGateway(s *Server) error {
// glog.Fatal(err)
// }
// }

1 change: 1 addition & 0 deletions eApi/internal/server/grpc/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ func (srv *Server) Ping(c context.Context, req *api.Request) (*api.Reply, error)
log.Debug().Msgf("ping msg: %v, count: %v", msg, p.Count)
return res, nil
}

1 change: 1 addition & 0 deletions eApi/internal/server/grpc/ping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ func TestPing(t *testing.T) {
So(err, ShouldEqual, ErrInternalError)
})
}

1 change: 1 addition & 0 deletions eApi/internal/server/grpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,4 @@ func (s *Server) Start() {
func (srv *Server) Stop() {
// ???
}

1 change: 1 addition & 0 deletions eApi/internal/server/grpc/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,4 @@ func (srv *Server) DeleteUser(c context.Context, uid *api.UidT) (*api.Empty, err
log.Info().Int64("uid", uid.Uid).Msg("failed to delete user")
return empty, nil
}

Loading

0 comments on commit 7409812

Please sign in to comment.