Command micro
A deployment tools for TP-Micro micro service framework.
Feature
- Quickly create a tp-micro project
- Run tp-micro project with hot compilation
Install
go install
Generate project
micro gen
command help:
NAME:
micro gen - Generate a tp-micro project
USAGE:
micro gen [command options] [arguments...]
OPTIONS:
--template value, -t value The template for code generation(relative/absolute)
--app_path value, -p value The path(relative/absolute) of the project
example: micro gen -t ./__tp-micro__tpl__.go -p ./myant
or default micro gen myant
- template file
__tp-micro__tpl__.go
demo:
// package __TPL__ is the project template
package __TPL__
// __API__PULL__ register PULL router:
// /home
// /math/divide
type __API__PULL__ interface {
Home(*struct{}) *HomeResult
Math
}
// __API__PUSH__ register PUSH router:
// /stat
type __API__PUSH__ interface {
Stat(*StatArg)
}
// MODEL create model
type __MODEL__ struct {
DivideArg
User
}
// Math controller
type Math interface {
// Divide handler
Divide(*DivideArg) *DivideResult
}
// HomeResult home result
type HomeResult struct {
Content string // text
}
type (
// DivideArg divide api arg
DivideArg struct {
// dividend
A float64
// divisor
B float64 `param:"<range: 0.01:100000>"`
}
// DivideResult divide api result
DivideResult struct {
// quotient
C float64
}
)
// StatArg stat handler arg
type StatArg struct {
Ts int64 // timestamps
}
// User user info
type User struct {
Id int64
Name string
Age int32
}
- The template generated by
micro gen
command.
├── __tp-micro__gen__.lock
├── .gitignore
├── README.md
├── __tp-micro__tpl__.go
├── api
│ ├── handler.gen.go
│ ├── handler.go
│ ├── router.gen.go
│ └── router.go
├── args
│ ├── const.go
│ ├── type.gen.go
│ ├── type.go
│ └── var.go
├── config
│ └── config.yaml
├── config.go
├── demo
├── log
│ └── PID
├── logic
│ ├── model
│ │ ├── divide_arg.gen.go
│ │ ├── init.go
│ │ └── user.gen.go
│ └── tmp_code.gen.go
├── main.go
├── rerrs
│ └── rerrs.go
└── sdk
├── rpc.gen.go
├── rpc.gen_test.go
├── rpc.go
└── rpc_test.go
Desc:
- This
micro gen
command only covers files with the ".gen.go" suffix if the __tp-micro__gen__.lock
file exists
- Add
.gen
suffix to the file name of the automatically generated file
tmp_code.gen.go
is temporary code used to ensure successful compilation!
When the project is completed, it should be removed!
Generated Default Sample
Run project
micro run
command help:
NAME:
micro run - Compile and run gracefully (monitor changes) an any existing go project
USAGE:
micro run [options] [arguments...]
or
micro run [options except -app_path] [arguments...] {app_path}
OPTIONS:
--watch_exts value, -x value Specified to increase the listening file suffix (default: ".go", ".ini", ".yaml", ".toml", ".xml")
--notwatch value, -n value Not watch files or directories
--app_path value, -p value The path(relative/absolute) of the project
example: micro run -x .yaml -p myant
or micro run