trytry-based-on-looklook

Putting go-zero into practice locally and personally.

API related

  1. Template generation
goctl api -o production.api
  1. 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)
}
  1. Format
goctl api format --dir .
  1. Generation
goctl api go -api production.api -dir ../

Model related

  1. Template Generation

// Path: apps/production
// With: cache, fundamental table, target foler
goctl model mysql datasource --url="root:[email protected](127.0.0.1:3306)/trytry" -table="production_brand" -c -dir=./model
  1. Update etc/production-api.yaml

Name: production-api
Host: 0.0.0.0
Port: 10001
Mode: dev

DB:
  DataSource: root:[email protected](127.0.0.1:3306)/micro?charset=utf8mb4&parseTime=true&loc=UTC
Cache:
  - Host: 127.0.0.1:6379
    Pass: redispwd
  1. 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
}

GitHub

View Github