generate

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenGraphCommand

func GenGraphCommand() *cobra.Command

GenGraphCommand generate graph command

func ListSubDirs

func ListSubDirs(root string, subDir string) ([]string, error)

ListSubDirs lists all subdirectories of the given root directory that have the given subdirectory name.

Types

type App

type App struct {
	Name                  string `yaml:"name" json:"name"`
	EnableTrace           bool   `yaml:"enableTrace" json:"enableTrace"`
	RegistryDiscoveryType string `yaml:"registryDiscoveryType" json:"registryDiscoveryType"`
	CacheType             string `yaml:"cacheType" json:"cacheType"`
}

type Database

type Database struct {
	Driver        string `yaml:"driver" json:"driver"`
	Mysql         DbAddr `yaml:"mysql" json:"mysql"`
	Redis         DbAddr `yaml:"redis" json:"redis"`
	Mongodb       DbAddr `yaml:"mongodb" json:"mongodb"`
	Postgresql    DbAddr `yaml:"postgresql" json:"postgresql"`
	Sqlite        DbAddr `yaml:"sqlite" json:"sqlite"`
	Oracle        DbAddr `yaml:"oracle" json:"oracle"`
	SQLServer     DbAddr `yaml:"sqlserver" json:"sqlserver"`
	Cassandra     DbAddr `yaml:"cassandra" json:"cassandra"`
	InfluxDB      DbAddr `yaml:"influxdb" json:"influxdb"`
	Elasticsearch DbAddr `yaml:"elasticsearch" json:"elasticsearch"`
	Clickhouse    DbAddr `yaml:"clickhouse" json:"clickhouse"`
	Cockroachdb   DbAddr `yaml:"cockroachdb" json:"cockroachdb"`
	Tidb          DbAddr `yaml:"tidb" json:"tidb"`
}

type DbAddr

type DbAddr struct {
	Dsn    string `yaml:"dsn" json:"dsn"`
	DBFile string `yaml:"dbFile" json:"dbFile"` // sqlite
}

type GenericConfig

type GenericConfig struct {
	App        App          `yaml:"app" json:"app"`
	Grpc       Grpc         `yaml:"grpc" json:"grpc"`
	GrpcClient []GrpcClient `yaml:"grpcClient" json:"grpcClient"`
	HTTP       HTTP         `yaml:"http" json:"http"`
	HTTPClient []HTTPClient `yaml:"httpClient" json:"httpClient"`

	// database config, match 2 configuration modes, one is separate configuration, the other is unified configuration
	Database      Database               `yaml:"database" json:"database"`
	Mysql         map[string]interface{} `yaml:"mysql" json:"mysql"`
	Redis         map[string]interface{} `yaml:"redis" json:"redis"`
	Mongodb       map[string]interface{} `yaml:"mongodb" json:"mongodb"`
	Postgresql    map[string]interface{} `yaml:"postgresql" json:"postgresql"`
	Sqlite        map[string]interface{} `yaml:"sqlite" json:"sqlite"`
	Oracle        map[string]interface{} `yaml:"oracle" json:"oracle"`
	SQLServer     map[string]interface{} `yaml:"sqlserver" json:"sqlserver"`
	Cassandra     map[string]interface{} `yaml:"cassandra" json:"cassandra"`
	InfluxDB      map[string]interface{} `yaml:"influxdb" json:"influxdb"`
	Elasticsearch map[string]interface{} `yaml:"elasticsearch" json:"elasticsearch"`
	Clickhouse    map[string]interface{} `yaml:"clickhouse" json:"clickhouse"`
	Cockroachdb   map[string]interface{} `yaml:"cockroachdb" json:"cockroachdb"`
	Tidb          map[string]interface{} `yaml:"tidb" json:"tidb"`

	// mq config, match 2 configuration modes, one is separate configuration, the other is unified configuration
	MqClient []MqClient             `yaml:"mqClient" json:"mqClient"`
	Rabbitmq map[string]interface{} `yaml:"rabbitmq" json:"rabbitmq"`
	Kafka    map[string]interface{} `yaml:"kafka" json:"kafka"`
	Activemq map[string]interface{} `yaml:"activemq" json:"activemq"`
	Rocketmq map[string]interface{} `yaml:"rocketmq" json:"rocketmq"`
	Nats     map[string]interface{} `yaml:"nats" json:"nats"`
	Nsq      map[string]interface{} `yaml:"nsq" json:"nsq"`
	Asynq    map[string]interface{} `yaml:"asynq" json:"asynq"`
	Pulsar   map[string]interface{} `yaml:"pulsar" json:"pulsar"`
	Zeromq   map[string]interface{} `yaml:"zeromq" json:"zeromq"`
	// contains filtered or unexported fields
}

func ParseYaml

func ParseYaml(configFile string, isAll bool) (*GenericConfig, error)

ParseYaml parses the YAML file and returns a GenericConfig, yaml file content example:

app:

name: "eshop-gw"

# http server settings example http:

port: 8080
timeout: 0

# http client settings example httpClient:

# grpc server settings example grpc:

port: 8282
httpPort: 8283

# grpc client settings example grpcClient:

  • name: "user" host: "127.0.0.1" port: 18282
  • name: "order" host: "127.0.0.1" port: 28282

# db settings example database:

mysql:
  dsn: "root:123456@(192.168.3.37:3306)/eshop_order?parseTime=true&loc=Local&charset=utf8,utf8mb4"
mongodb:
  dsn: "root:123456@192.168.3.37:27017/account?connectTimeoutMS=15000"

# or redis:

dsn: "default:123456@192.168.3.37:6379/0"

postgresql:

dsn: "root:123456@192.168.3.37:5432/account?sslmode=disable"

# mq settings example kafka:

mode: "producer,consumer"
brokers: ["192.168.3.37:9092"]

rabbitmq:

mode: "consumer"
host: "192.168.3.37"
port: 5672

func (*GenericConfig) GetDependencies

func (c *GenericConfig) GetDependencies(serviceName string) (map[string][]string, []Service)

GetDependencies returns the dependencies of the service.

func (*GenericConfig) GetServiceName

func (c *GenericConfig) GetServiceName() string

GetServiceName returns the name of the service.

func (*GenericConfig) GetServiceType

func (c *GenericConfig) GetServiceType() string

GetServiceType returns the type of the service.

type Grpc

type Grpc struct {
	HTTPPort int `yaml:"httpPort" json:"httpPort"`
	Port     int `yaml:"port" json:"port"`
}

type GrpcClient

type GrpcClient struct {
	Host string `yaml:"host" json:"host"`
	Name string `yaml:"name" json:"name"`
	Port int    `yaml:"port" json:"port"`
}

type HTTP

type HTTP struct {
	Port    int `yaml:"port" json:"port"`
	Timeout int `yaml:"timeout" json:"timeout"`
}

type HTTPClient

type HTTPClient struct {
	BaseURL string `yaml:"baseURL" json:"baseURL"`
	Name    string `yaml:"name" json:"name"`
}

type MqClient

type MqClient struct {
	Name string `yaml:"name" json:"name"` // rabbitmq, kafka, activemq, rocketmq, nats, nsq, redis, asynq, pulsar, zeromq, etc.
	Mode string `yaml:"mode" json:"mode"` // producer, consumer.

	Rabbitmq map[string]interface{} `yaml:"rabbitmq" json:"rabbitmq"`
	Kafka    map[string]interface{} `yaml:"kafka" json:"kafka"`
	Activemq map[string]interface{} `yaml:"activemq" json:"activemq"`
	Rocketmq map[string]interface{} `yaml:"rocketmq" json:"rocketmq"`
	Nats     map[string]interface{} `yaml:"nats" json:"nats"`
	Nsq      map[string]interface{} `yaml:"nsq" json:"nsq"`
	Redis    map[string]interface{} `yaml:"redis" json:"redis"`
	Asynq    map[string]interface{} `yaml:"asynq" json:"asynq"`
	Pulsar   map[string]interface{} `yaml:"pulsar" json:"pulsar"`
	Zeromq   map[string]interface{} `yaml:"zeromq" json:"zeromq"`
}

type ProjectConfig

type ProjectConfig struct {
	Services []Service `yaml:"services"`
}

ProjectConfig represents the configuration of the project.

func NewProjectConfig

func NewProjectConfig() *ProjectConfig

NewProjectConfig creates a new ProjectConfig.

func (*ProjectConfig) AddService

func (c *ProjectConfig) AddService(config *GenericConfig)

AddService adds a new service to the project configuration.

type Service

type Service struct {
	Name         string              `yaml:"name"`         // service name
	Type         string              `yaml:"type"`         // http, grpc, db, mq
	Dependencies map[string][]string `yaml:"dependencies"` // map[Type][]serviceName
}

Service represents a service in the project.

Jump to

Keyboard shortcuts

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