common

package
v0.0.0-...-0deb007 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2020 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KC_RAND_KIND_NUM   = 0 // 纯数字
	KC_RAND_KIND_LOWER = 1 // 小写字母
	KC_RAND_KIND_UPPER = 2 // 大写字母
	KC_RAND_KIND_ALL   = 3 // 数字、大小写字母
)
View Source
const (
	// For use with functions that take an expiration time.
	NoExpiration time.Duration = -1
)

Variables

This section is empty.

Functions

func CmpPasswd

func CmpPasswd(pwd string, solt string, sendpwd string) bool

func CreateHTTPClient

func CreateHTTPClient(cfg *Config) *http.Client

CreateHTTPClient return a http client instannce

func FileExist

func FileExist(path string) bool

checks whether a file or directory exists. It returns false when the file or directory does not exist.

func GenPasswd

func GenPasswd(pwd string, pwdlen int) (string, string)

func Krand

func Krand(size int, kind int) []byte

随机字符串

func ReadFile

func ReadFile(path string) string

*

  • 根据path读取文件中的内容,返回字符串
  • 建议使用绝对路径,例如:"./schema/search/appoint.json"

func SendHTTPReq

func SendHTTPReq(cfg *Config, method, addr, urlpath string, reqBody []byte) (rspBody []byte, err error)

SendHTTPReq ...

func SendHTTPReqWithClient

func SendHTTPReqWithClient(client *http.Client, cfg *Config, method, addr, urlpath string, reqBody []byte) (rspBody []byte, err error)

SendHTTPReqWithClient ...

Types

type BaseService

type BaseService struct {
	Cfg *Config
	// contains filtered or unexported fields
}

func NewBaseService

func NewBaseService(cfg *Config, name string, svc Service) *BaseService

func (*BaseService) Auth

func (s *BaseService) Auth(u, p string) bool

func (*BaseService) HTTPDelete

func (s *BaseService) HTTPDelete(addr, urlpath string) (err error)

HTTPDelete return the body of the response when send http get method to the server

func (*BaseService) HTTPGet

func (s *BaseService) HTTPGet(addr, urlpath string) (rspBody []byte, err error)

HTTPGet return the body of the response when send http get method to the server

func (*BaseService) HTTPPost

func (s *BaseService) HTTPPost(addr, urlpath string, reqBody []byte) (rspBody []byte, err error)

HTTPPost return the body of the response when send http get method to the server

func (*BaseService) IsRunning

func (s *BaseService) IsRunning() bool

Implements Service

func (*BaseService) OnStart

func (s *BaseService) OnStart(c *Config, e *httprouter.Router) error

func (*BaseService) OnStop

func (s *BaseService) OnStop(c *Config, e *httprouter.Router)

Implements Service

func (*BaseService) Start

func (s *BaseService) Start() error

func (*BaseService) Stop

func (s *BaseService) Stop() bool

type Cache

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

func NewCache

func NewCache(cleanupInterval time.Duration) *Cache

Return a new cache with a given cleanup interval. If the cleanup interval is less than one, expired items are not deleted from the cache before calling c.DeleteExpired().

func (Cache) Add

func (c Cache) Add(k string, x interface{}, d time.Duration) error

Add an item to the cache only if an item doesn't already exist for the given key, or if the existing item has expired. Returns an error otherwise.

func (Cache) Clear

func (c Cache) Clear()

Delete all items from the cache.

func (Cache) Delete

func (c Cache) Delete(k string)

Delete an item from the cache. Does nothing if the key is not in the cache.

func (Cache) DeleteExpired

func (c Cache) DeleteExpired()

Delete all expired items from the cache.

func (Cache) Get

func (c Cache) Get(k string) (interface{}, bool)

Get an item from the cache. Returns the item or nil, and a bool indicating whether the key was found.

func (Cache) ItemCount

func (c Cache) ItemCount() int

Returns the number of items in the cache. This may include items that have expired, but have not yet been cleaned up. Equivalent to len(c.Items()).

func (Cache) OnEvicted

func (c Cache) OnEvicted(f func(string, interface{}))

Sets an (optional) function that is called with the key and value when an item is evicted from the cache. (Including when it is deleted manually, but not when it is overwritten.) Set to nil to disable.

func (Cache) Replace

func (c Cache) Replace(k string, x interface{}, d time.Duration) error

Set a new value for the cache key only if it already exists, and the existing item hasn't expired. Returns an error otherwise.

func (Cache) Set

func (c Cache) Set(k string, x interface{}, d time.Duration)

Add an item to the cache, replacing any existing item. If it is -1 (NoExpiration), the item never expires.

func (Cache) UpdateExpiration

func (c Cache) UpdateExpiration(k string, Expiration int64) error

type Config

type Config struct {
	Server bool //是否为服务端

	Name string

	DownDir string //只有客户端才配置

	Log string

	Net struct {
		IP       string
		MgntPort int
		DataPort int

		AgentMgntPort int
		AgentDataPort int
	}

	Auth struct {
		Username string
		Password string
	}

	Control *Control
}

定义配置映射的结构体

func ParserConfig

func ParserConfig(c *Config) (*Config, error)

func ReadJson

func ReadJson(path string) Config

type Control

type Control struct {
	Speed     int
	MaxActive int
	CacheSize int
}

type Item

type Item struct {
	Object     interface{}
	Expiration int64
}

func (Item) Expired

func (item Item) Expired() bool

Returns true if the item has expired.

type Service

type Service interface {
	Start() error
	Stop() bool
	OnStart(c *Config, e *httprouter.Router) error
	OnStop(c *Config, e *httprouter.Router)
	IsRunning() bool
}

Jump to

Keyboard shortcuts

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