app

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package app provides configuration management for the application. It includes structures for various configuration aspects such as system settings, logging, databases, caching, and external service integrations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	Driver string `json:"driver"` // Cache driver
	Prefix string `json:"prefix"` // Cache key prefix
}

Cache defines caching configuration options.

type Config

type Config struct {
	System    SysConfig   `json:"system"`    // System-wide configuration
	Log       LogConfig   `json:"log"`       // Logging configuration
	Databases []Databases `json:"databases"` // Database configurations
	Cache     Cache       `json:"cache"`     // Caching configuration
	Redis     []Redis     `json:"redis"`     // Redis configurations
	Kafka     Kafka       `json:"kafka"`     // Kafka configuration
	Monitor   Monitor     `json:"monitor"`   // Monitoring configuration
	Feishu    Feishu      `json:"feishu"`    // Feishu (Lark) configuration
}

Config represents the entire application configuration.

func GetConfig

func GetConfig() *Config

GetConfig returns the global configuration object. This function should be called after LoadConfig has been executed.

Returns:

  • *Config: A pointer to the global configuration structure.

Example usage:

cfg := GetConfig()
fmt.Printf("Application name: %s\n", cfg.System.Name)

func LoadConfig

func LoadConfig() (*Config, error)

LoadConfig loads the application configuration from a JSON file. It determines the configuration file to load based on the runtime environment, unmarshal the JSON content into a Config struct, and performs some post-processing.

The function uses environment variables to determine the runtime environment and application name. If these are not set, it falls back to default values.

Returns:

  • *Config: A pointer to the loaded configuration structure.
  • error: An error if any occurred during the loading process.

type Databases

type Databases struct {
	Enable        bool          `json:"enable"`                     // Database enable flag
	DbType        string        `json:"db_type"`                    // Database type
	DbHost        string        `json:"db_host"`                    // Database host
	DbName        string        `json:"db_name"`                    // Database name
	DbUsername    string        `json:"db_username,omitempty"`      // Database username
	DbPassword    string        `json:"db_password,omitempty"`      // Database password
	DbMaxIdleConn int           `json:"db_max_idle_conn,omitempty"` // Maximum number of idle connections in the pool
	DbMaxOpenConn int           `json:"db_max_open_conn,omitempty"` // Maximum number of open connections to the database
	DbMaxLifetime time.Duration `json:"db_max_lifetime,omitempty"`  // Maximum amount of time a connection may be reused (in hours)
	AuthMechanism string        `json:"auth_mechanism"`             // Authentication mechanism (for MongoDB)
}

Databases defines database configuration options.

type Feishu

type Feishu struct {
	Enable       bool   `json:"enable"`        // Feishu integration enable flag
	GroupWebhook string `json:"group_webhook"` // Feishu group webhook URL
	AppID        string `json:"app_id"`        // Feishu application ID
	AppSecret    string `json:"app_secret"`    // Feishu application secret
	EncryptKey   string `json:"encrypt_key"`   // Encryption key for Feishu messages
}

Feishu defines Feishu (Lark) configuration options.

type Kafka

type Kafka struct {
	Brokers            []string `json:"brokers"`              // Kafka broker addresses
	MaxRetry           int      `json:"max_retry"`            // Maximum number of retries
	ClientID           string   `json:"client_id"`            // Kafka client ID
	ProducerEnable     bool     `json:"producer_enable"`      // Producer enable flag
	ConsumerEnable     bool     `json:"consumer_enable"`      // Consumer enable flag
	ConsumerGroup      string   `json:"consumer_group"`       // Consumer group name
	ConsumerTopics     []string `json:"consumer_topics"`      // Topics to consume
	ConsumerAutoSubmit bool     `json:"consumer_auto_submit"` // Auto-submit consumer offsets flag
}

Kafka defines Kafka configuration options.

type LogConfig

type LogConfig struct {
	Driver  string `json:"driver"`   // Log driver: "stdout" or "file"
	Level   string `json:"level"`    // Log level: "debug", "info", "warn", "error", "fatal"
	LogPath string `json:"log_path"` // Log file path (only used when Driver is "file")
}

LogConfig defines logging configuration options.

type Monitor

type Monitor struct {
	PanicRobot PanicRobot `json:"panic_robot"` // Panic robot configuration
}

Monitor defines monitoring configuration options.

type PanicRobot

type PanicRobot struct {
	Enable bool        `json:"enable"` // Panic robot enable flag
	Wechat robotConfig `json:"wechat"` // WeChat's configuration for panic reporting
	Feishu robotConfig `json:"feishu"` // Feishu configuration for panic reporting
}

PanicRobot defines configuration for panic reporting.

type Redis

type Redis struct {
	Name        string        `json:"name"`         // Redis connection name
	Enable      bool          `json:"enable"`       // Redis enable flag
	Host        string        `json:"host"`         // Redis host
	Auth        string        `json:"auth"`         // Redis authentication
	MaxIdle     int           `json:"max_idle"`     // Maximum number of idle connections in the pool
	MaxActive   int           `json:"max_active"`   // Maximum number of connections allocated by the pool at a given time
	IdleTimeout time.Duration `json:"idle_timeout"` // Close connections after remaining idle for this duration (in minutes)
	Prefix      string        `json:"prefix"`       // Redis key prefix
	DB          int           `json:"db"`           // Redis database number
}

Redis defines Redis configuration options.

type SysConfig

type SysConfig struct {
	Name         string        `json:"name"`          // Application name
	RunMode      string        `json:"run_mode"`      // Running mode
	HTTPPort     string        `json:"http_port"`     // HTTP server port
	ReadTimeout  time.Duration `json:"read_timeout"`  // Maximum request timeout
	WriteTimeout time.Duration `json:"write_timeout"` // Maximum response timeout
	Version      string        `json:"version"`       // Application version
	RootPath     string        `json:"root_path"`     // Root directory path
	DebugMode    bool          `json:"debug_mode"`    // Debug mode flag
	LangDir      string        `json:"lang_dir"`      // Language files directory
	DefaultLang  string        `json:"default_lang"`  // Default language
	EnvKey       string        `json:"env_key"`       // Environment key for reading runtime environment
	JwtSecret    string        `json:"jwt_secret"`    // JWT secret for authentication
	TokenExpire  time.Duration `json:"token_expire"`  // JWT token expiration time (in seconds)
	Env          string        `json:"env"`           // Runtime environment
}

SysConfig defines system-wide configuration options.

Directories

Path Synopsis
http
controller/auth
Package auth provides authentication-related functionality for the application.
Package auth provides authentication-related functionality for the application.
middleware
Package middleware provides HTTP middleware functions for the application.
Package middleware provides HTTP middleware functions for the application.
router
Package router handles the routing for the application.
Package router handles the routing for the application.
job
Package job provides functionality for registering and managing scheduled jobs in the application.
Package job provides functionality for registering and managing scheduled jobs in the application.
monitor
Package monitor provides monitoring functionalities for various system aspects.
Package monitor provides monitoring functionalities for various system aspects.
model
auth
Package auth provides authentication and authorization functionalities.
Package auth provides authentication and authorization functionalities.
pkg
e
Package e defines error codes and messages used throughout the go-api project.
Package e defines error codes and messages used throughout the go-api project.
jwt
Package jwt provides functionality for generating and parsing JSON Web Tokens (JWT) specifically for application authentication in the go-api project.
Package jwt provides functionality for generating and parsing JSON Web Tokens (JWT) specifically for application authentication in the go-api project.
schedule
Package schedule provides functionality for scheduling and managing jobs in a distributed environment.
Package schedule provides functionality for scheduling and managing jobs in a distributed environment.
trace
Package trace provides functionality for generating unique trace identifiers.
Package trace provides functionality for generating unique trace identifiers.
repository
auth
Package auth provides functionality for authentication and authorization, including operations for managing application entities.
Package auth provides functionality for authentication and authorization, including operations for managing application entities.

Jump to

Keyboard shortcuts

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