util

package module
v0.0.0-...-a723b66 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2018 License: MIT Imports: 21 Imported by: 0

README

Introduction

An utilities package for Golang project

Installing

go get -u github.com/jackypanster/util

Examples

  • Queue
util.InitQueue(64, 65536)
util.JobQueue <- util.Job {
    Do: func() error {
        // do something
        return nil
    }
}
  • Array
src := []string{"a", "a", "a"}
dst := util.Uniq(src)
  • Redis

  • MongoDB

  • Log

Documentation

Index

Constants

View Source
const (
	HIGH uint = iota
	NORMAL
	LOW
)

Variables

View Source
var JobQueue chan Job
View Source
var Letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
View Source
var TraditionalDict = map[string]string{}/* 2542 elements not displayed */

Functions

func CheckArray

func CheckArray(values []string, name string) []string

func CheckCondition

func CheckCondition(condition bool, description string)

func CheckErr

func CheckErr(err error)

func CheckErrf

func CheckErrf(err error, description string)

func CheckMap

func CheckMap(m map[string]string, name string) map[string]string

func CheckMapInf

func CheckMapInf(m map[string]interface{}, name string) map[string]interface{}

func CheckNil

func CheckNil(v interface{}, name string)

func CheckStr

func CheckStr(value string, name string) string

func Contains

func Contains(s []string, e string) bool

func Convert

func Convert(text string) string

func ConvertDateString

func ConvertDateString(date string) int64

func ConvertTimestamp

func ConvertTimestamp(timestamp string) time.Time

func Decode

func Decode(str string, v interface{}) error

func DoRequest

func DoRequest(url string, body string) (string, error)

func Encode

func Encode(v interface{}) (string, error)

func Get

func Get(targetUrl string, debug bool) (string, error)

func GetBool

func GetBool(key string) bool

func GetInt

func GetInt(key string) int

func GetNowMillionSecond

func GetNowMillionSecond() int64

func GetNumber

func GetNumber(version string) int

func GetPool

func GetPool(url string, password string, db int) *redis.Pool

func GetRedisPool

func GetRedisPool(url string) *redis.Pool

func GetString

func GetString(key string) string

func GetStringSlice

func GetStringSlice(key string) []string

func InitConfig

func InitConfig()

func InitQueue

func InitQueue(maxWorkers int, queueSize int)

func Min

func Min(x, y int) int

func NewMgoSession

func NewMgoSession(url string, mode mgo.Mode) *mgo.Session

func NewMongoSession

func NewMongoSession(host string, port int) *mgo.Session

func NewRedisPool

func NewRedisPool(host string, port int) *redis.Pool

func Post

func Post(targetUrl string, content string, debug bool) (string, error)

func RandomAny

func RandomAny(n int) string

func RandomInt

func RandomInt(min int, max int) int

func RandomStr

func RandomStr(n int) string

func Sign

func Sign(input string) string

func ToInstance

func ToInstance(str string, v interface{}) error

func ToJsonString

func ToJsonString(v interface{}) (string, error)

func Uniq

func Uniq(src []string) []string

Types

type Dispatcher

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

func NewDispatcher

func NewDispatcher(maxWorkers int) *Dispatcher

func (*Dispatcher) Run

func (d *Dispatcher) Run()

func (*Dispatcher) Workload

func (d *Dispatcher) Workload() int

type Entity

type Entity struct {
	ID           string    `json:"id" bson:"id"`
	Date         string    `json:"date" bson:"date"`
	Name         string    `json:"name" bson:"name"`
	Milliseconds int64     `json:"milliseconds" bson:"milliseconds"`
	Timestamp    time.Time `json:"timestamp" bson:"timestamp"`
}

type Job

type Job struct {
	Do func() error
}

Job represents the job to be run

type Log

type Log struct {
	*zap.SugaredLogger
}

func NewDevLog

func NewDevLog() *Log

func NewProductLog

func NewProductLog(file string) *Log

type Operator

type Operator interface {
	All(interface{}) error
	Insert(interface{}) error
	Update(interface{}, interface{}) error
	Remove(string) error
	Empty() error
	Find(string, interface{}) error
	FindByDate(string, interface{}) error
	FindByName(string, interface{}) error
	FindByTimestamp(string, string, interface{}) error
	FindOne(interface{}, interface{}) error
	Search(interface{}, interface{}) error
	Exists(query interface{}) bool
}

type RedisService

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

func NewRedisService

func NewRedisService(pool *redis.Pool, list string) *RedisService

func (*RedisService) Get

func (self *RedisService) Get(key string, result interface{}) error

func (*RedisService) HGETALL

func (self *RedisService) HGETALL(hash string) (map[string]int, error)

func (*RedisService) HINCRBY

func (self *RedisService) HINCRBY(hash string, key string, val int) error

func (*RedisService) Lpop

func (self *RedisService) Lpop() (string, error)

func (*RedisService) Rpush

func (self *RedisService) Rpush(v interface{}) error

func (*RedisService) Set

func (self *RedisService) Set(key string, v interface{}, ttl int) error

func (*RedisService) Size

func (self *RedisService) Size() (int, error)

type Service

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

func NewService

func NewService(session *mgo.Session, database string, table string, size int) *Service

func (*Service) All

func (self *Service) All(results interface{}) error

func (*Service) Empty

func (self *Service) Empty() error

func (*Service) Exists

func (self *Service) Exists(query interface{}) bool

func (*Service) Find

func (self *Service) Find(id string, result interface{}) error

func (*Service) FindByDate

func (self *Service) FindByDate(date string, results interface{}) error

func (*Service) FindByName

func (self *Service) FindByName(name string, results interface{}) error

func (*Service) FindByTimestamp

func (self *Service) FindByTimestamp(start string, end string, results interface{}) error

func (*Service) FindOne

func (self *Service) FindOne(query interface{}, result interface{}) error

func (*Service) Insert

func (self *Service) Insert(doc interface{}) error

func (*Service) Remove

func (self *Service) Remove(id string) error

func (*Service) Search

func (self *Service) Search(query interface{}, results interface{}) error

func (*Service) Update

func (self *Service) Update(selector interface{}, update interface{}) error

type Task

type Task struct {
	ID       string      `json:"id"`
	Priority uint        `json:"priority"`
	Time     time.Time   `json:"time"`
	Retries  uint        `json:"retries"`
	Content  interface{} `json:"content"`
}

func NewTask

func NewTask(id string, content interface{}) Task

type TaskService

type TaskService struct {
	*RedisService
}

func NewTaskService

func NewTaskService(redisService *RedisService) *TaskService

func (*TaskService) Deq

func (self *TaskService) Deq() (*Task, error)

func (*TaskService) Enq

func (self *TaskService) Enq(content interface{}) error

type Worker

type Worker struct {
	WorkerPool chan chan Job
	JobChannel chan Job
	// contains filtered or unexported fields
}

Worker represents the worker that executes the job

func NewWorker

func NewWorker(workerPool chan chan Job) *Worker

func (*Worker) SetId

func (w *Worker) SetId(num int)

func (*Worker) Start

func (w *Worker) Start()

Start method starts the run loop for the worker, listening for a quit channel in case we need to stop it

func (*Worker) Stop

func (w *Worker) Stop()

Stop method signals the worker to stop listening for work requests

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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