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
microv6 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 -p ./myapp
or default micro gen myapp
- The initial template file
__tp-micro__tpl__.go
:
// package __TPL__ is the project template
package __TPL__
// __API_CALL__ register CALL router:
// /home
// /math/divide
type __API_CALL__ interface {
Home(*struct{}) *HomeResult
Math
}
// __API_PUSH__ register PUSH router:
// /stat
type __API_PUSH__ interface {
Stat(*StatArg)
}
// __MYSQL_MODEL__ create mysql model
type __MYSQL_MODEL__ struct {
User
Log
Device
}
// __MONGO_MODEL__ create mongodb model
type __MONGO_MODEL__ struct {
Meta
}
// 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 `key:"pri"`
Name string `key:"uni"`
Age int32
}
type Log struct {
Text string
}
type Device struct {
UUID string `key:"pri"`
}
type Meta struct {
Hobby []string
Tags []string
}
- The template generated by
micro gen
command.
├── README.md
├── __tp-micro__gen__.lock
├── __tp-micro__tpl__.go
├── api
│ ├── handler.go
│ ├── pull_handler.gen.go
│ ├── push_handler.gen.go
│ ├── router.gen.go
│ └── router.go
├── args
│ ├── const.gen.go
│ ├── const.go
│ ├── type.gen.go
│ ├── type.go
│ └── var.go
├── config
│ └── config.yaml
├── config.go
├── doc
│ ├── APIDoc.md
│ ├── README.md
│ └── databases.md
├── log
│ └── PID
├── logic
│ ├── model
│ │ ├── init.go
│ │ ├── mongo_meta.gen.go
│ │ ├── mysql_device.gen.go
│ │ ├── mysql_log.gen.go
│ │ └── mysql_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
microv6 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
is temporary code used to ensure successful compilation!
When the project is completed, it should be removed!
- The type of handler's parameter and result must be struct!
- You can modify the created template file
__tp-micro__tpl__.go
, and run the microv6 gen
command again to update the project
Generated Default Sample
Create README.md(only)
microv6 newdoc
command help:
NAME:
microv6 newdoc - Generate a tp-micro project README.md
USAGE:
microv6 newdoc [command options] [arguments...]
OPTIONS:
--app_path value, -p value The path(relative/absolute) of the project
Run project
microv6 run
command help:
NAME:
microv6 run - Compile and run gracefully (monitor changes) an any existing go project
USAGE:
microv6 run [options] [arguments...]
or
microv6 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: microv6 run -x .yaml -p myapp
or microv6 run
Add model
Add mysql model struct code to project template.
microv6 tpl
command help:
NAME:
microv6 tpl - Add mysql model struct code to project template
USAGE:
microv6 tpl [command options] [arguments...]
OPTIONS:
--app_path value, -p value The path(relative/absolute) of the project
--host value mysql host ip (default: "localhost")
--port value mysql host port (default: "3306")
--username value, --user value mysql username (default: "root")
--password value, --pwd value mysql password
--db value mysql database (default: "test")
--table value mysql table
--ssh_user value ssh user
--ssh_host value ssh host ip
--ssh_port value ssh host port