winter

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2019 License: MIT Imports: 28 Imported by: 0

README

Winter

Base on gin

Features

  • support apollo
  • support nacos
  • support config file

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultTimestampFormat default timestamp format
	DefaultTimestampFormat = "2006-01-02 15:04:05"
)
View Source
var (
	// Log log
	Log = DefaultLogger()
)

Functions

func Cwd

func Cwd() (cwd string, err error)

Cwd returns current work directory

func GetValue

func GetValue(key string) interface{}

GetValue returns config value by config key

func GetValueWithDefault

func GetValueWithDefault(key string, options ConfigEntityGetOptions) interface{}

GetValueWithDefault returns config value by config key

func IsFileExist

func IsFileExist(filePath string) bool

IsFileExist judges target file exists or not

func MapGet

func MapGet(m map[interface{}]interface{}, key string, defaultValue interface{}) interface{}

MapGet returns value by key with defaultValue

func NewError

func NewError(msg string, err error) error

NewError returns new error

func StructToURLValues

func StructToURLValues(m interface{}) url.Values

StructToURLValues converts struct to url.Values

Types

type ApolloConfig

type ApolloConfig struct {
	Meta       string   `json:"meta"`
	AppID      string   `json:"appId"`
	Cluster    string   `json:"cluster"`
	Namespaces []string `json:"namespaces"`
}

ApolloConfig stores apollo configurations

type ApolloEntity

type ApolloEntity struct {
	// contains filtered or unexported fields
}

ApolloEntity provides an ability to get config value by config key from apollo

func (*ApolloEntity) Get

func (apolloEntity *ApolloEntity) Get(key string) interface{}

Get returns config value by config key

type Application

type Application struct {
	Name     string `json:"name"`
	BasePath string `json:"basePath"`
}

Application stores application configuration

type Config

type Config struct {
	ENV                      string         `json:"env"`
	App                      Application    `json:"app"`
	Server                   Server         `json:"server"`
	Static                   Static         `json:"static"`
	ConfigFileConfigurations Configurations `json:"configurations"`
	// contains filtered or unexported fields
}

Config stores default and custom configuration

ENV: "dev" or "prod"

func (*Config) GetValue

func (config *Config) GetValue(configKey string, options ConfigEntityGetOptions) interface{}

GetValue returns config value by config key

type ConfigEntity

type ConfigEntity interface {
	Get(key string) interface{}
}

ConfigEntity provides an ability to get config value by config key

type ConfigEntityGetOptions

type ConfigEntityGetOptions struct {
	DefaultValue interface{}
}

ConfigEntityGetOptions stores get options

type Configurations

type Configurations map[string]interface{}

Configurations stores all configurations

type Data

type Data map[string]string

Data http post method parameters

type HTTPOptions

type HTTPOptions struct {
	Data    Data
	Params  Params
	Headers Headers
}

HTTPOptions option

type HTTPService

type HTTPService interface {
	Get(path string, options HTTPOptions) (Result, error)
	Post(path string, options HTTPOptions) (Result, error)
}

HTTPService provides an ability to call service

func Service

func Service(serviceName string, options ServiceOptions) (httpService HTTPService, err error)

Service return httpService

type Headers

type Headers map[string]string

Headers headers

type Logger

type Logger interface {
	Trace(args interface{})
	Debug(args interface{})
	Info(args interface{})
	Warn(args interface{})
	Error(args interface{})
	Fatal(args interface{})
	Panic(args interface{})
	resty.Logger
}

Logger interface

type LogrusLogger

type LogrusLogger struct {
	// contains filtered or unexported fields
}

LogrusLogger logger

func DefaultLogger

func DefaultLogger() *LogrusLogger

DefaultLogger returns a default logger TODO performance

func (LogrusLogger) Debug

func (logger LogrusLogger) Debug(args interface{})

Debug debug

func (LogrusLogger) Debugf

func (logger LogrusLogger) Debugf(format string, v ...interface{})

Debugf debugf

func (LogrusLogger) Error

func (logger LogrusLogger) Error(args interface{})

Error error

func (LogrusLogger) Errorf

func (logger LogrusLogger) Errorf(format string, v ...interface{})

Errorf errorf

func (LogrusLogger) Fatal

func (logger LogrusLogger) Fatal(args interface{})

Fatal fatal

func (LogrusLogger) Info

func (logger LogrusLogger) Info(args interface{})

Info info

func (LogrusLogger) Panic

func (logger LogrusLogger) Panic(args interface{})

Panic panic

func (LogrusLogger) Trace

func (logger LogrusLogger) Trace(args interface{})

Trace trace

func (LogrusLogger) Warn

func (logger LogrusLogger) Warn(args interface{})

Warn warn

func (LogrusLogger) Warnf

func (logger LogrusLogger) Warnf(format string, v ...interface{})

Warnf warnf

type NacosClient

type NacosClient struct {
	// contains filtered or unexported fields
}

NacosClient provides an ability to

func NewNacosClientWithConfig

func NewNacosClientWithConfig(config map[interface{}]interface{}) (nacosClient *NacosClient, err error)

NewNacosClientWithConfig returns nacos client via config

func (*NacosClient) GetHTTPService

func (nacosClient *NacosClient) GetHTTPService(serviceName string, options ServiceOptions) (httpService HTTPService, err error)

GetHTTPService returns a http service to use service

func (*NacosClient) SetLogger

func (nacosClient *NacosClient) SetLogger(l resty.Logger)

SetLogger sets nacos httpClient's logger

type NacosConfig

type NacosConfig struct {
	Client constant.ClientConfig `mapstructure:",squash"`
	Server constant.ServerConfig `mapstructure:",squash"`
}

NacosConfig nacos config

type NacosHTTPService

type NacosHTTPService struct {
	// contains filtered or unexported fields
}

NacosHTTPService nacosHTTPService

func (NacosHTTPService) Get

func (httpService NacosHTTPService) Get(path string, options HTTPOptions) (result Result, err error)

Get provides an ability to get response via http GET method

func (NacosHTTPService) Post

func (httpService NacosHTTPService) Post(path string, options HTTPOptions) (result Result, err error)

Post provides an ability to get response via http POST method

type NacosHttpResult

type NacosHttpResult struct {
	// contains filtered or unexported fields
}

func (NacosHttpResult) JSON

func (httpResult NacosHttpResult) JSON(container interface{}) error

JSON returns response as JSONObject

func (NacosHttpResult) Raw

func (httpResult NacosHttpResult) Raw() []byte

func (NacosHttpResult) String

func (httpResult NacosHttpResult) String() string

String returns response as string

type Params

type Params map[string]string

Params http get method parameters

type Result

type Result interface {
	String() string
	JSON(content interface{}) error
	Raw() []byte
}

Result handles with response

type Server

type Server struct {
	Host string `json:"host"`
	Port int    `json:"port"`
}

Server stores server configuration

type ServiceDiscovery

type ServiceDiscovery interface {
	GetHTTPService(serviceName string, options ServiceOptions) (HTTPService, error)
}

ServiceDiscovery provides an ability to call service

type ServiceOptions

type ServiceOptions map[string]interface{}

ServiceOptions stores service options

type Static

type Static struct {
	URLPrefix string `json:"urlPrefix"`
	Root      string `json:"root"`
}

Static static assets

type TextFormatter

type TextFormatter struct {
	TimestampFormat string
	FieldMap        map[string]interface{}
	AppName         string
}

TextFormatter text format

func (*TextFormatter) Format

func (formatter *TextFormatter) Format(entry *logrus.Entry) ([]byte, error)

Format implements logrus.Formatter

type Winter

type Winter struct {
	// contains filtered or unexported fields
}

Winter winter

func Default

func Default() *Winter

Default create Winter instance

func (*Winter) DELETE

func (winter *Winter) DELETE(relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes

DELETE handles delete request

func (*Winter) GET

func (winter *Winter) GET(relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes

GET handles get request

func (*Winter) Group

func (winter *Winter) Group(relativePath string, handlers ...gin.HandlerFunc) *gin.RouterGroup

func (*Winter) IsComing

func (winter *Winter) IsComing(addr ...string)

IsComing bootstrap http server

func (*Winter) OPTIONS

func (winter *Winter) OPTIONS(relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes

OPTIONS handles options request

func (*Winter) POST

func (winter *Winter) POST(relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes

POST handles post request

func (*Winter) PUT

func (winter *Winter) PUT(relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes

PUT handles put request

func (*Winter) Use

func (winter *Winter) Use(middlewares ...gin.HandlerFunc)

Use middleware

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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