Documentation ¶
Index ¶
- Constants
- func CmpPasswd(pwd string, solt string, sendpwd string) bool
- func CreateHTTPClient(cfg *Config) *http.Client
- func FileExist(path string) bool
- func GenPasswd(pwd string, pwdlen int) (string, string)
- func Krand(size int, kind int) []byte
- func ReadFile(path string) string
- func SendHTTPReq(cfg *Config, method, addr, urlpath string, reqBody []byte) (rspBody []byte, err error)
- func SendHTTPReqWithClient(client *http.Client, cfg *Config, method, addr, urlpath string, reqBody []byte) (rspBody []byte, err error)
- type BaseService
- func (s *BaseService) Auth(u, p string) bool
- func (s *BaseService) HTTPDelete(addr, urlpath string) (err error)
- func (s *BaseService) HTTPGet(addr, urlpath string) (rspBody []byte, err error)
- func (s *BaseService) HTTPPost(addr, urlpath string, reqBody []byte) (rspBody []byte, err error)
- func (s *BaseService) IsRunning() bool
- func (s *BaseService) OnStart(c *Config, e *httprouter.Router) error
- func (s *BaseService) OnStop(c *Config, e *httprouter.Router)
- func (s *BaseService) Start() error
- func (s *BaseService) Stop() bool
- type Cache
- func (c Cache) Add(k string, x interface{}, d time.Duration) error
- func (c Cache) Clear()
- func (c Cache) Delete(k string)
- func (c Cache) DeleteExpired()
- func (c Cache) Get(k string) (interface{}, bool)
- func (c Cache) ItemCount() int
- func (c Cache) OnEvicted(f func(string, interface{}))
- func (c Cache) Replace(k string, x interface{}, d time.Duration) error
- func (c Cache) Set(k string, x interface{}, d time.Duration)
- func (c Cache) UpdateExpiration(k string, Expiration int64) error
- type Config
- type Control
- type Item
- type Service
Constants ¶
const ( KC_RAND_KIND_NUM = 0 // 纯数字 KC_RAND_KIND_LOWER = 1 // 小写字母 KC_RAND_KIND_UPPER = 2 // 大写字母 KC_RAND_KIND_ALL = 3 // 数字、大小写字母 )
const ( // For use with functions that take an expiration time. NoExpiration time.Duration = -1 )
Variables ¶
This section is empty.
Functions ¶
func CreateHTTPClient ¶
CreateHTTPClient return a http client instannce
func FileExist ¶
checks whether a file or directory exists. It returns false when the file or directory does not exist.
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) 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 ¶
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 ¶
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) 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 ¶
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 ¶
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 ¶
Add an item to the cache, replacing any existing item. If it is -1 (NoExpiration), the item never expires.
func (Cache) UpdateExpiration ¶
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 }
定义配置映射的结构体