trytry-based-on-looklook
Putting go-zero into practice locally and personally.
API related
- Template generation
goctl api -o production.api
- Api files import and group
import (
"./car/car.api"
"./brand/brand.api"
)
@server(
group: carGrp
prefix: api/production/car
)
service production-api {
@handler CarNew
post /estb(CarNewReq) returns(CarNewResp)
@handler CarInfo
post /info(CarInfoReq) returns(CarInfoResp)
}
- Format
goctl api format --dir .
- Generation
goctl api go -api production.api -dir ../
Model related
- Template Generation
// Path: apps/production
// With: cache, fundamental table, target foler
goctl model mysql datasource --url="root:root@tcp(127.0.0.1:3306)/trytry" -table="production_brand" -c -dir=./model
- Update
etc/production-api.yaml
Name: production-api
Host: 0.0.0.0
Port: 10001
Mode: dev
DB:
DataSource: root:root@tcp(127.0.0.1:3306)/micro?charset=utf8mb4&parseTime=true&loc=UTC
Cache:
- Host: 127.0.0.1:6379
Pass: redispwd
- Update
internal/config/config.go
package config
import (
"github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/rest"
)
type Config struct {
rest.RestConf
DB struct {
DataSource string
}
Cache cache.CacheConf
}