conf

package
v0.0.0-...-f4276bb Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	Name string `json:"name" toml:"name"`
}

type Config

type Config struct {
	App *App `json:"app" toml:"app"`
	// [mysql]
	MongoDB *mongodb `json:"mysql" toml:"mysql"`
	// [http]
	Http *Http `json:"http" toml:"http"`
	// [grpc]
	Grpc *Grpc `json:"grpc" toml:"grpc"`
	// [kafka]
	Kafka *Kafka `json:"kafka" toml:"kafka"`
}

程序的配置对象 config --> object

func C

func C() *Config

把全局对象保护起来

func DefaultConfig

func DefaultConfig() *Config

func LoadConfigFromEnv

func LoadConfigFromEnv() (*Config, error)

func LoadConfigFromToml

func LoadConfigFromToml(path string) (*Config, error)

func (*Config) String

func (c *Config) String() string

格式化成一个json

type Grpc

type Grpc struct {
	Host string `json:"host" toml:"host" env:"GRPC_HOST"`
	Port int    `json:"port" toml:"port" env:"GRPC_PORT"`
}

func NewDefaultGrpc

func NewDefaultGrpc() *Grpc

func (*Grpc) Address

func (h *Grpc) Address() string

type Http

type Http struct {
	Host string `json:"host" toml:"host" env:"HTTP_HOST"`
	Port int    `json:"port" toml:"port" env:"HTTP_PORT"`
}

func (*Http) Address

func (h *Http) Address() string

type Kafka

type Kafka struct {
	Brokers []string `toml:"brokers" env:"brokers"`
	GroupId string   `toml:"group_id" env:"group_id"`
	Topic   string   `toml:"topic" env:"topic"`
}

定义Producer的配置

func NewDefaultKafka

func NewDefaultKafka() *Kafka

Jump to

Keyboard shortcuts

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