config

package
v1.9.7 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultStyle = "go_zero"

Variables

View Source
var (
	CfgFile    string
	CfgEnvFile string
)

Functions

func InitConfig

func InitConfig(rootCmd *cobra.Command) error

func MarshalDebugJSONForCommand

func MarshalDebugJSONForCommand(cfg Config, cmd *cobra.Command) ([]byte, error)

MarshalDebugJSONForCommand marshals the effective config for the active command path.

func ResetConfig

func ResetConfig()

func SetConfig

func SetConfig(command string, flagSet *pflag.FlagSet) error

func TraverseCommands

func TraverseCommands(prefix string, cmd *cobra.Command) error

Types

type AddApiConfig

type AddApiConfig struct{}

type AddConfig

type AddConfig struct {
	Output string `mapstructure:"output"`

	Api          AddApiConfig          `mapstructure:"api"`
	Proto        AddProtoConfig        `mapstructure:"proto"`
	Sql          AddSqlConfig          `mapstructure:"sql"`
	SqlMigration AddSqlMigrationConfig `mapstructure:"sql-migration"`
}

type AddProtoConfig

type AddProtoConfig struct{}

type AddSqlConfig

type AddSqlConfig struct{}

type AddSqlMigrationConfig

type AddSqlMigrationConfig struct{}

type Config

type Config struct {
	// config file only
	Hooks HooksConfig `mapstructure:"hooks"`

	// root persistent flags
	Debug bool `mapstructure:"debug"`

	Quiet          bool     `mapstructure:"quiet"`
	DebugSleepTime int      `mapstructure:"debug-sleep-time"`
	RegisterTplVal []string `mapstructure:"register-tpl-val"`
	Home           string   `mapstructure:"home"`
	Style          string   `mapstructure:"style"`

	// new command
	New NewConfig `mapstructure:"new"`

	// add command
	Add AddConfig `mapstructure:"add"`

	// gen command
	Gen GenConfig `mapstructure:"gen"`

	// template command
	Template TemplateConfig `mapstructure:"template"`

	// upgrade command
	Upgrade UpgradeConfig `mapstructure:"upgrade"`

	// migrate command
	Migrate MigrateConfig `mapstructure:"migrate"`

	// format command
	Format FormatConfig `mapstructure:"format"`
}
var C Config

C global command flags

func (*Config) ApiDir

func (c *Config) ApiDir() string

func (*Config) HomeDir

func (c *Config) HomeDir() string

func (*Config) ProtoDir

func (c *Config) ProtoDir() string

func (*Config) ProtoDirs added in v1.7.0

func (c *Config) ProtoDirs() []string

ProtoDirs 返回 RPC proto 扫描根列表。未配置时回落 desc/proto,保持旧行为。

func (*Config) SqlDir

func (c *Config) SqlDir() string

func (*Config) ToolVersion

func (c *Config) ToolVersion() ToolVersion

func (*Config) Wd

func (c *Config) Wd() string

type FormatConfig

type FormatConfig struct {
	GitChange   bool `mapstructure:"git-change"`
	DisplayDiff bool `mapstructure:"display-diff"`
}

type GenConfig

type GenConfig struct {
	Hooks HooksConfig `mapstructure:"hooks"`

	Desc                    []string `mapstructure:"desc"`
	DescIgnore              []string `mapstructure:"desc-ignore"`
	GitChange               bool     `mapstructure:"git-change"`
	ApiTypesDir             string   `mapstructure:"api-types-dir"`
	Route2Code              bool
	ProtoDirs               []string `mapstructure:"proto-dir"` // RPC proto 扫描根,空则回落 desc/proto
	ProtoInclude            []string `mapstructure:"proto-include"`
	RpcClient               bool     `mapstructure:"rpc-client"`
	ModelDriver             string   `mapstructure:"model-driver"`
	ModelStrict             bool     `mapstructure:"model-strict"`
	ModelIgnoreColumns      []string `mapstructure:"model-ignore-columns"`
	ModelIgnoreColumnsTable []struct {
		Table   string   `mapstructure:"table"`
		Columns []string `mapstructure:"columns"`
	} `mapstructure:"model-ignore-columns-table"`
	ModelSchema           string   `mapstructure:"model-schema"`
	ModelDatasource       bool     `mapstructure:"model-datasource"`
	ModelDatasourceUrl    []string `mapstructure:"model-datasource-url"`
	ModelDatasourceTable  []string `mapstructure:"model-datasource-table"`
	ModelCache            bool     `mapstructure:"model-cache"`
	ModelCacheTable       []string `mapstructure:"model-cache-table"`
	ModelCachePrefix      string   `mapstructure:"model-cache-prefix"`
	ModelCacheExpiryTable []struct {
		Table          string `mapstructure:"table"`
		Expiry         int64  `mapstructure:"expiry"`
		NotFoundExpiry int64  `mapstructure:"not-found-expiry"`
	} `mapstructure:"model-cache-expiry-table"`

	// Gen Sub Command
	Swagger GenSwaggerConfig `mapstructure:"swagger"`
}

type GenSwaggerConfig

type GenSwaggerConfig struct {
	Desc       []string `mapstructure:"desc"`
	DescIgnore []string `mapstructure:"desc-ignore"`
	Output     string   `mapstructure:"output"`
	Route2Code bool     `mapstructure:"route2code"`
	Merge      bool     `mapstructure:"merge"`
}

type HooksConfig

type HooksConfig struct {
	Before []string `mapstructure:"before"`
	After  []string `mapstructure:"after"`
}

type MigrateConfig

type MigrateConfig struct {
	Driver             string `mapstructure:"driver"`
	DataSourceUrl      string `mapstructure:"datasource-url"`
	Source             string `mapstructure:"source"`
	SourceAppendDriver bool   `mapstructure:"source-append-driver"`
	XMigrationsTable   string `mapstructure:"x-migrations-table"`
}

type NewConfig

type NewConfig struct {
	Name                 string   `mapstructure:"name"`                  // 新建项目名称
	Module               string   `mapstructure:"module"`                // 新建的项目的 go module
	Mono                 bool     `mapstructure:"mono"`                  // 是否是 mono 项目(即在一个mod项目之下, 但该项目本身无 go.mod 文件)
	Output               string   `mapstructure:"output"`                // 输出到的目录
	Remote               string   `mapstructure:"remote"`                // 远程仓库地址
	RemoteTimeout        int      `mapstructure:"remote-timeout"`        // 远程仓库超时时间, 单位秒
	Cache                bool     `mapstructure:"cache"`                 // 当使用远程仓库时是否使用缓存
	Gen                  bool     `mapstructure:"gen"`                   // 新建项目后是否自动执行 gen 命令
	RemoteAuthUsername   string   `mapstructure:"remote-auth-username"`  // 远程仓库的认证用户名
	RemoteAuthPassword   string   `mapstructure:"remote-auth-password"`  // 远程仓库的认证密码
	Frame                string   `mapstructure:"frame"`                 // 使用 pzero 内置的框架
	Branch               string   `mapstructure:"branch"`                // 使用远程模板仓库的某个分支
	Local                string   `mapstructure:"local"`                 // 使用本地模板与 branch 对应
	Features             []string `mapstructure:"features"`              // 新建项目使用哪些特性, 灵活构建模板
	Ignore               []string `mapstructure:"ignore"`                // 忽略哪些文件或目录
	IgnoreExtra          []string `mapstructure:"ignore-extra"`          // 忽略哪些额外的文件或目录
	ExecutableExtensions []string `mapstructure:"executable-extensions"` // 可执行文件的后缀
}

type TemplateBuildConfig

type TemplateBuildConfig struct {
	Output     string   `mapstructure:"output"`
	WorkingDir string   `mapstructure:"working-dir"`
	Name       string   `mapstructure:"name"`
	Ignore     []string `mapstructure:"ignore"`
}

type TemplateConfig

type TemplateConfig struct {
	Init  TemplateInitConfig  `mapstructure:"init"`
	Build TemplateBuildConfig `mapstructure:"build"`
}

type TemplateInitConfig

type TemplateInitConfig struct {
	Output string `mapstructure:"output"`
	Remote string `mapstructure:"remote"`
	Branch string `mapstructure:"branch"`
}

type ToolVersion

type ToolVersion struct {
	ProtocVersion             *version.Version
	GoctlVersion              *version.Version
	ProtocGenGoVersion        *version.Version
	ProtocGenGoGrpcVersion    *version.Version
	ProtocGenOpenapiv2Version *version.Version
}
var (
	ToolVersionOnce  sync.Once
	ToolVersionValue ToolVersion
)

type UpgradeConfig

type UpgradeConfig struct {
	Channel string `mapstructure:"channel"`
}

Jump to

Keyboard shortcuts

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