config

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: May 17, 2024 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 1 more Imports: 22 Imported by: 0

Documentation

Overview

Package config provides configuration-related capabilities for this project.

Index

Constants

This section is empty.

Variables

View Source
var SupportValidate = map[string]bool{
	"go": true,
}

SupportValidate defines whether a certain language supports validation. Validation code will be generated only when: 1. The language appears as a key in this map. 2. The corresponding value is true.

View Source
var TRPCCliVersion = "v1.0.9"

TRPCCliVersion is the version of trpc-cmdline tool.

Functions

func CurrentTemplatePath

func CurrentTemplatePath() (dir string, err error)

CurrentTemplatePath gets the installation path of the trpc configuration file, which is installed to $HOME/.trpc-cmdline-assets.

func Init

func Init(opts ...Option) (string, error)

Init initializes the configuration. If the configuration file trpc.yaml is missing, or the code template is missing, or the configuration version does not match, the configuration is automatically installed. After the initialization is successful, returns the path of config file's directory.

func SetupDependencies

func SetupDependencies(deps []*Dependency) error

SetupDependencies configures dependency installation.

func UninstallTemplate

func UninstallTemplate()

UninstallTemplate cleans up installed templates.

Types

type Config

type Config struct {
	Domain     string                          `yaml:"domain"` // host in importPath
	TplFileExt string                          `yaml:"tpl_file_ext"`
	IDL        map[string]*Dependency          `yaml:"idl"`       // IDL name -> IDL tool
	Tools      map[string][]*Dependency        `yaml:"tools"`     // Programming language -> Dependency tools
	Plugins    map[string][]string             `yaml:"plugins"`   // Programming language -> Dependency plugins
	Templates  map[string]map[string]*Template `yaml:"templates"` // idltype -> Code templates for each language
}

Config is the global config.

func GlobalConfig

func GlobalConfig() Config

GlobalConfig returns global config.

func LoadConfig

func LoadConfig() (cfg *Config, err error)

LoadConfig loads trpc config.

type Dependency

type Dependency struct {
	Executable  string `yaml:"executable"`   // Executable file name.
	VersionMin  string `yaml:"version_min"`  // Min version.
	VersionCmd  string `yaml:"version_cmd"`  // Max version.
	ArtifactURL string `yaml:"artifact_url"` // Artifact download URL.
	Repository  string `yaml:"repository"`   // Repository URL.
	MD5         string `yaml:"md5"`          // md5 sum up.
	Fallback    string `yaml:"fallback"`     // Failure prompt.
}

Dependency is the description of dependencies.

func LoadDependencies

func LoadDependencies(languages ...string) ([]*Dependency, error)

LoadDependencies loads the configuration on demand based on the given language type.

func (*Dependency) CheckVersion

func (d *Dependency) CheckVersion() (passed bool, error error)

CheckVersion check if installed version meet the version requirement.

func (*Dependency) Installed

func (d *Dependency) Installed() bool

Installed checks installed or not.

func (*Dependency) TryInstallTo

func (d *Dependency) TryInstallTo(path string) error

TryInstallTo tries to install the dependency to the given path.

type IDLType

type IDLType uint

IDLType is IDL type.

const (
	IDLTypeProtobuf    IDLType = iota // IDL is protobuf
	IDLTypeFlatBuffers                // IDL is flatbuffers
	IDLTypeInvalid
)

Related constants of IDL type.

func (IDLType) String

func (t IDLType) String() string

String Return the description of the IDL type.

func (IDLType) Valid

func (t IDLType) Valid() bool

Valid Check if the IDL type is valid.

type LanguageTemplates

type LanguageTemplates map[string]*Template

LanguageTemplates is the templates for each programming language.

type OpSys

type OpSys struct {
	Name    string   `yaml:"name"`
	Imports []string `yaml:"imports"`
}

OpSys is the system of operation (运营体系).

type Option

type Option func(*options)

Option is the option provided for config.Init.

func WithForce

func WithForce(force bool) Option

WithForce sets whether to force initialize the asset files, i.e. extract the files inside the binary to overwrite the existing files located at $HOME/.trpc-cmdline-assets. Default is false.

type Template

type Template struct {
	Language    string `yaml:"language"`      // Programming language
	LangFileExt string `yaml:"lang_file_ext"` // Source file extension for the programming language
	// The output filename for the stub corresponds to: service name + separator + original file name
	Separator string `yaml:"separator"`
	// Keep the original file name as a suffix for the generated files
	KeepOrigName bool `yaml:"keep_orig_name"`
	// Follow the camelcase style for generated file names
	CamelCaseName     bool     `yaml:"camelcase_name"`
	AssetDir          string   `yaml:"asset_dir"`            // Code template directory
	RPCServerStub     string   `yaml:"rpc_server_stub"`      // Server stub
	RPCServerTestStub string   `yaml:"rpc_server_test_stub"` // Server test stub
	RPCClientStub     []string `yaml:"rpc_client_stub"`      // Client stub
	// Whether the client stub includes all service definitions
	RPCClientStubPerService bool `yaml:"rpc_client_stub_per_service"`
}

Template is language templates.

func GetTemplate

func GetTemplate(idl IDLType, lang string) (*Template, error)

GetTemplate returns the corresponding configuration information based on the given index of the serialization protocol and the language type.

Jump to

Keyboard shortcuts

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