- 快召唤伙伴们来围观吧
- 微博 QQ QQ空间 贴吧
- 文档嵌入链接
- 复制
- 微信扫一扫分享
- 已成功复制到剪贴板
敏捷工程实践与规范 廖强 PHPCON2018
深入介绍G7在产品研发过程中去除重复性工作的技术规范、细节和背后的思考,以及G7的技术体系如何平衡效率和规范的冲突。
展开查看详情
1 .
2 .
3 .
4 .API
5 . swagger:meta // Schemes: http, https // Host: localhost // BasePath: /v2 // Version: 0.0.1 // License: MIT http://opensource.org/licenses/MIT // Contact: liaoqiang<liaoqiang@g7> http://www.g7.com.cn // // Consumes: // - application/json // - application/xml // // Produces: // - application/json // - application/xml // // swagger:meta
6 .swagger:route // swagger:route GET /pets pets listPets // // Lists pets filtered by some parameters. // // This will show all available pets by default. // You can get the pets that are out of stock // // Consumes: // - application/json // - application/x-protobuf // // Produces: // - application/json // - application/x-protobuf // // Schemes: http, https, ws, wss // // Security: // api_key: // oauth: read, write // // Responses: // - default: genericError // - 200: someResponse // - 422: validationError
7 . swagger:params // swagger:parameters get_goods_by_id type GetGoodsByIDReq struct { // ID // in : path // Required : true GoodsID uint64 `json:"goods_id"` // Sku 0 1- 2- // in : query // Required : false SkuCheckState int8 `json:"sku_check_state"` // Sku 0 1- 2- // in : query // Required : false SkuOnlineState int8 `json:"sku_online_state"` }
8 . swagger:response // A ValidationError is an error that is used when the required input fails validation. // swagger:response validationError type ValidationError struct { // The error message // in: body Body struct { // The validation message // // Required: true Message string // An optional field name to which this validation applies FieldName string } }
9 .swagger:model // User represents the user for this application // // A user is the security principal for this application. // It's also used as one of main axes for reporting. // // swagger:model type User struct { // the id for this user // // required: true // min: 1 ID int64 `json:"id"` // the name for this user // required: true // min length: 3 Name string `json:"name"` // the email address for this user // // required: true Email Email `json:"login"` // the friends for this user Friends []User `json:"friends"` }
10 .• swagger:allOf • swagger:strfmt • swagger: security
11 .• •
12 .func main() { router := gin.Default() v1 := router.Group("/v1") { v1.POST("/login", loginEndpoint) v1.POST("/submit", submitEndpoint) v1.POST("/read", readEndpoint) } v2 := router.Group("/v2") { v2.POST("/login", loginEndpoint) v2.POST("/submit", submitEndpoint) v2.POST("/read", readEndpoint) } router.Run(":8080") }
13 .type GetGoodsByIDReq struct { // ID GoodsID uint64 `json:”goods_id" in:”path” validate:”@uint64[1,]”` // Sku 0 1- 2- SkuCheckState int8 `json:”sku_check_state" in:”query” default:”0”` // Sku 0 1- 2- SkuOnlineState int8 `json:”sku_online_state" in:”query” default:”0”` }
14 .type ErrorField struct { // // // {“name":{ "alias" : "test"}} alias "name.alias" // alias , 2 a ”name.alias[2].a" Field string `name:"field"` // Msg string `name:"msg"` // // body, query, header, path, formData In string `name:"in"` } type ErrorFields []*ErrorField type StatusError struct { // Key Key string `name:"key"` // Code int64 `name:"code"` // Msg string `name:"msg"` // CanDisplay bool `name:"canDisplay"` // Source []string `name:"source"` // ID ID string `name:"id"` // ErrorFields ErrorFields `name:"errorFields"` }
15 .
16 .// swagger:enum type CertType uint8 // const ( CERT_TYPE_UNKNOWN CertType = iota CERT_TYPE__ID_CARD // CERT_TYPE__PASSPORT // )
17 .
18 .
19 .//go:generate tools gen model --with-comments --database DBContractMgr Contract // @def primary ID // @def unique_index I_from From FromID type Contract struct { // id ID uint64 `db:"F_id" json:"contractId,string" sql:"bigint unsigned NOT NULL"` // From types.BusinessFrom `db:"F_from" json:"from" sql:"tinyint unsigned NOT NULL"` // id FromID string `db:"F_from_id" json:"fromId" sql:"varchar(64) NOT NULL"` // Enabled enumeration.Bool `db:"F_enabled" json:"-" sql:"tinyint unsigned NOT NULL"` // presets.OperateTime }
20 .client
21 .// go:generate tools gen client --spec-url http://xxxxx.com/user // go:generate tools gen client --spec-url http://xxxxx.com/data // go:generate tools gen client --spec-url http://xxxxx.com/pic
22 .
23 .
24 .Mock
25 .
26 .var Config = struct { Log *log.Log Server transport_http.ServeHTTP Upload client_upload.ClientUpload `conf:"env"` MasterDB mysql.MySQL }{ Log: &log.Log{ Level: "DEBUG", }, Server: transport_http.ServeHTTP{ WithCORS: true, Port: 8000, }, Upload: client_upload.ClientUpload{ Client: client.Client{ Host: “service-upload—customerinfo.xxx.com", }, }, MasterDB: mysql.MySQL{ Name: "service-contract-mgr", Host: "staging.xxx.com", User: "root", Password: "root", }, }
27 .
28 .CI Flow
29 .