config

package
v1.7.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 3, 2024 License: MIT Imports: 11 Imported by: 73

README

配置项管理

名称 是否可选 说明
namingFormat YES 文件名称格式化符

naming-format

namingFormat可以用于对生成代码的文件名称进行格式化,和日期格式化符(yyyy-MM-dd)类似,在代码生成时可以根据这些配置项的格式化符进行格式化。

格式化符(gozero)

格式化符由go,zero组成,如常见的三种格式化风格你可以这样编写:

  • lower: gozero
  • camel: goZero
  • snake: go_zero

常见格式化符生成示例 源字符:welcome_to_go_zero

格式化符 格式化结果 说明
gozero welcometogozero 小写
goZero welcomeToGoZero 驼峰
go_zero welcome_to_go_zero snake
Go#zero Welcome#to#go#zero #号分割Title类型
GOZERO WELCOMETOGOZERO 大写
_go#zero_ _welcome#to#go#zero_ 下划线做前后缀,并且#分割

错误格式化符示例

  • go
  • gOZero
  • zero
  • goZEro
  • goZERo
  • goZeRo
  • tal

使用方法

目前可通过在生成api、rpc、model时通过--style参数指定format格式,如:

goctl api go test.api -dir . -style gozero
 goctl rpc proto -src test.proto -dir . -style go_zero
goctl model mysql datasource -url="" -table="*" -dir ./snake -style GoZero

默认值

当不指定-style时默认值为gozero

Documentation

Index

Constants

View Source
const (
	// DefaultFormat defines a default naming style
	DefaultFormat = "gozero"
)

Variables

View Source
var (
	// Cmd describes a bug command.
	Cmd = cobrax.NewCommand("config")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// NamingFormat is used to define the naming format of the generated file name.
	// just like time formatting, you can specify the formatting style through the
	// two format characters go, and zero. for example: snake format you can
	// define as go_zero, camel case format you can it is defined as goZero,
	// and even split characters can be specified, such as go#zero. in theory,
	// any combination can be used, but the prerequisite must meet the naming conventions
	// of each operating system file name.
	// Note: NamingFormat is based on snake or camel string
	NamingFormat string `yaml:"namingFormat"`
}

Config defines the file naming style

func NewConfig

func NewConfig(format string) (*Config, error)

NewConfig creates an instance for Config

type External added in v1.6.5

type External struct {
	// Model is the configuration for the model code generation.
	Model Model `yaml:"model,omitempty"`
}

Config defines the file naming style

func GetExternalConfig added in v1.6.6

func GetExternalConfig() (*External, error)

type Model added in v1.6.5

type Model struct {
	// TypesMap: custom Data Type Mapping Table.
	TypesMap map[string]ModelTypeMapOption `yaml:"types_map,omitempty" `
}

Model defines the configuration for the model code generation.

type ModelTypeMapOption added in v1.6.5

type ModelTypeMapOption struct {
	// Type: valid when not using UnsignedType and NullType.
	Type string `yaml:"type"`

	// UnsignedType: valid when not using  NullType.
	UnsignedType string `yaml:"unsigned_type,omitempty"`

	// NullType: priority use.
	NullType string `yaml:"null_type,omitempty"`

	// Pkg defines the package of the custom type.
	Pkg string `yaml:"pkg,omitempty"`
}

ModelTypeMapOption custom Type Options.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL