core

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2020 License: BSD-2-Clause Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const None = "NONE"

Variables

View Source
var APIMethod = MethodEnum{
	GET:     &MethodValue{Value: "GET"},
	POST:    &MethodValue{Value: "POST"},
	PUT:     &MethodValue{Value: "PUT"},
	DELETE:  &MethodValue{Value: "DELETE"},
	OPTIONS: &MethodValue{Value: "OPTIONS"},
}

APIMethod Published enum

View Source
var APIStatus = &StatusEnum{
	Ok:           "OK",
	Error:        "ERROR",
	Invalid:      "INVALID",
	NotFound:     "NOT_FOUND",
	Forbidden:    "FORBIDDEN",
	Existed:      "EXISTED",
	Unauthorized: "UNAUTHORIZED",
}

APIStatus Published enum

View Source
var DbStatus = &DbStatusEnum{
	Ok:       "OK",
	Error:    "ERROR",
	NotFound: "NOT_FOUND",
}
View Source
var HTTPMethods = &HTTPMethodEnum{
	Get:    "GET",
	Post:   "POST",
	Put:    "PUT",
	Head:   "HEAD",
	Delete: "DELETE",
	Option: "OPTION",
}

HTTPMethods Supported HTTP Method

Functions

This section is empty.

Types

type APIClientConfiguration

type APIClientConfiguration struct {
	Address       string
	Protocol      string
	Timeout       time.Duration
	MaxRetry      int
	WaitToRetry   time.Duration
	LoggingCol    string
	MaxConnection int
}

APIClientConfiguration

type APIResponse

type APIResponse struct {
	Status    string            `json:"status"`
	Data      interface{}       `json:"data,omitempty"`
	Message   string            `json:"message"`
	ErrorCode string            `json:"errorCode,omitempty"`
	Total     int64             `json:"total,omitempty"`
	Headers   map[string]string `json:"headers,omitempty"`
}

type App added in v0.0.2

type App struct {
	Name       string
	Server     *Server
	DBList     []*DBClient
	WorkerList []*Worker
	// contains filtered or unexported fields
}

App ..

func NewApp added in v0.0.2

func NewApp(name string) *App

NewApp Wrap application

func (*App) Launch added in v0.0.2

func (app *App) Launch() error

Launch Launch app

func (*App) OnAllDBConnected added in v0.0.2

func (app *App) OnAllDBConnected(task Task)

SetupDBClient ...

func (*App) SetupAPIServer added in v0.0.2

func (app *App) SetupAPIServer() (*Server, error)

SetupAPIServer ...

func (*App) SetupDBClient added in v0.0.2

func (app *App) SetupDBClient(config DBConfiguration) *DBClient

SetupDBClient ...

func (*App) SetupWorker added in v0.0.2

func (app *App) SetupWorker() *Worker

SetupWorker ...

type CallResult

type CallResult struct {
	RespCode     int                 `json:"respCode,omitempty" bson:"resp_code,omitempty"`
	RespHeader   map[string][]string `json:"respHeader,omitempty" bson:"resp_header,omitempty"`
	RespBody     *string             `json:"respBody,omitempty" bson:"resp_body,omitempty"`
	ResponseTime int64               `json:"responseTime,omitempty" bson:"response_time,omitempty"`
	ErrorLog     *string             `json:"errorLog,omitempty" bson:"error_log,omitempty"`
}

CallResult ...

type ConsumeFn

type ConsumeFn = func(*QueueItem) error

type DBClient

type DBClient struct {
	Name   string
	Config DBConfiguration
	// contains filtered or unexported fields
}

DBClient ..

func (*DBClient) Connect

func (client *DBClient) Connect() error

Connect ...

func (*DBClient) OnConnected

func (client *DBClient) OnConnected(fn OnConnectedHandler)

OnConnected ...

type DBConfiguration

type DBConfiguration struct {
	Address            []string
	Ssl                bool
	Username           string
	Password           string
	AuthDB             string
	ReplicaSetName     string
	SecondaryPreferred bool
}

DBConfiguration ...

type DBModel

type DBModel struct {
	ColName        string
	DBName         string
	TemplateObject interface{}
	// contains filtered or unexported fields
}

DBModel ...

func (*DBModel) Aggregate

func (m *DBModel) Aggregate(pipeline interface{}, result interface{}) error

Aggregate ...

func (*DBModel) Count

func (m *DBModel) Count(query interface{}) *DbResponse

Count Count object which matched with query.

func (*DBModel) Create

func (m *DBModel) Create(entity interface{}) *DbResponse

Create insert one object into DB

func (*DBModel) CreateIndex

func (m *DBModel) CreateIndex(index mgo.Index) error

CreateIndex ...

func (*DBModel) CreateMany

func (m *DBModel) CreateMany(entityList ...interface{}) *DbResponse

CreateMany insert many object into db

func (*DBModel) Delete

func (m *DBModel) Delete(selector interface{}) *DbResponse

Delete Delete all object which matched with selector

func (*DBModel) GetColWith

func (m *DBModel) GetColWith(s *DBSession) (*mgo.Collection, error)

GetColWith ...

func (*DBModel) GetFreshSession

func (m *DBModel) GetFreshSession() *DBSession

GetFreshSession ...

func (*DBModel) IncreOne

func (m *DBModel) IncreOne(query interface{}, fieldName string, value int) *DbResponse

IncreOne Increase one field of the document & return new value

func (*DBModel) Init

func (m *DBModel) Init(s *DBSession) error

Init ...

func (*DBModel) NewList

func (m *DBModel) NewList(limit int) interface{}

NewList return new object with same type of TemplateObject

func (*DBModel) NewObject

func (m *DBModel) NewObject() interface{}

NewObject return new object with same type of TemplateObject

func (*DBModel) Query

func (m *DBModel) Query(query interface{}, offset int, limit int, reverse bool) *DbResponse

Query Get all object in DB

func (*DBModel) QueryOne

func (m *DBModel) QueryOne(query interface{}) *DbResponse

QueryOne ...

func (*DBModel) QueryS

func (m *DBModel) QueryS(query interface{}, offset int, limit int, sortStr string) *DbResponse

QueryS Get all object in DB with orderby clause

func (*DBModel) Update

func (m *DBModel) Update(query interface{}, updater interface{}) *DbResponse

Update Update all matched item

func (*DBModel) UpdateOne

func (m *DBModel) UpdateOne(query interface{}, updater interface{}) *DbResponse

UpdateOne Update one matched object.

func (*DBModel) UpsertOne

func (m *DBModel) UpsertOne(query interface{}, updater interface{}) *DbResponse

UpsertOne Update one matched object, if notfound, create new document

type DBQueue2

type DBQueue2 struct {
	ColName string
	// contains filtered or unexported fields
}

DBQueue2 ...

func (*DBQueue2) Init

func (dbq *DBQueue2) Init(mSession *DBSession, dbName string)

Init ...

func (*DBQueue2) InitWithExpiredTime

func (dbq *DBQueue2) InitWithExpiredTime(mSession *DBSession, dbName string, expiredTime time.Duration)

Init ...

func (*DBQueue2) Push

func (dbq *DBQueue2) Push(data interface{}) error

func (*DBQueue2) PushWithKey

func (dbq *DBQueue2) PushWithKey(data interface{}, keys *[]string) error

func (*DBQueue2) StartConsumer

func (dbq *DBQueue2) StartConsumer(consumer ConsumeFn, channelNum int)

StartConsumer ...

type DBQueueChannel

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

type DBQueueConnector

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

DBQueueConnector ...

type DBSession

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

DBSession ..

func (*DBSession) Clone

func (s *DBSession) Clone() *DBSession

Clone : clone dbsession

func (*DBSession) Close

func (s *DBSession) Close()

Close : close db session

func (*DBSession) Copy

func (s *DBSession) Copy() *DBSession

Copy : copy dbsession

func (*DBSession) GetMGOSession

func (s *DBSession) GetMGOSession() *mgo.Session

GetMGOSession : get mgo session

func (*DBSession) Valid

func (s *DBSession) Valid() bool

Valid : check if session is active

type DbResponse

type DbResponse struct {
	Status    string      `json:"status"`
	Data      interface{} `json:"data,omitempty"`
	Message   string      `json:"message"`
	ErrorCode string      `json:"errorCode,omitempty"`
	Total     int64       `json:"total,omitempty"`
}

type DbStatusEnum

type DbStatusEnum struct {
	Ok       string
	Error    string
	NotFound string
}

type Error

type Error struct {
	Type    string
	Message string
	Data    interface{}
}

func (*Error) Error

func (e *Error) Error() string

type HTTPMethod

type HTTPMethod string

HTTPMethod ...

type HTTPMethodEnum

type HTTPMethodEnum struct {
	Get    HTTPMethod
	Post   HTTPMethod
	Put    HTTPMethod
	Head   HTTPMethod
	Delete HTTPMethod
	Option HTTPMethod
}

HTTPMethodEnum ...

type HandleFunc

type HandleFunc func(request Request) Response

type IPoll

type IPoll interface {
	Add(conn net.Conn) error
	Remove(conn net.Conn) error
	Wait(int64) ([]net.Conn, error)
}

type KQueue

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

func NewKQueue

func NewKQueue() *KQueue

func (*KQueue) Add

func (k *KQueue) Add(wsConn net.Conn) error

func (*KQueue) Remove

func (k *KQueue) Remove(wsConn net.Conn) error

func (*KQueue) Wait

func (k *KQueue) Wait(timeout int64) ([]net.Conn, error)

type LCache

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

LCache ...

func NewLCache

func NewLCache(maxItem int, ttl int) (m *LCache)

NewLCache ... maxItem: maximum item ttl: time to live (second)

func NewLCacheRefreshMode

func NewLCacheRefreshMode(maxItem int, ttl int, refreshTTL bool) (m *LCache)

NewLCacheRefreshMode ... maxItem: maximum item ttl: time to live (second) refreshTTL : if refreshTTL = true, when someone access item, ttl of item will be refresh

func (*LCache) Cleanup

func (c *LCache) Cleanup()

Cleanup Remove all data

func (*LCache) ContainsKey

func (c *LCache) ContainsKey(k string) (ok bool)

ContainsKey ...

func (*LCache) Get

func (c *LCache) Get(k string) (v interface{}, ok bool)

Get ...

func (*LCache) Len

func (c *LCache) Len() int

Len ...

func (*LCache) Put

func (c *LCache) Put(k string, v interface{})

Put ...

func (*LCache) Remove

func (c *LCache) Remove(k string)

Remove ...

type MethodEnum

type MethodEnum struct {
	GET     *MethodValue
	POST    *MethodValue
	PUT     *MethodValue
	DELETE  *MethodValue
	OPTIONS *MethodValue
}

MethodEnum ...

type MethodValue

type MethodValue struct {
	Value string
}

type OnConnectedHandler

type OnConnectedHandler = func(session *DBSession) error

OnConnectedHandler ...

type OutboundAPIRequest

type OutboundAPIRequest struct {
	Method  string            `json:"method" bson:"method"`
	Path    string            `json:"path" bson:"path"`
	Params  map[string]string `json:"params,omitempty" bson:"params,omitempty"`
	Headers map[string]string `json:"headers,headers" bson:"headers,omitempty"`
	Content string            `json:"content,omitempty" bson:"content,omitempty"`
}

OutboundAPIRequest Request to call other service

func NewOutboundAPIRequest

func NewOutboundAPIRequest(method string, path string, params map[string]string, content string, headers map[string]string) *OutboundAPIRequest

func (*OutboundAPIRequest) GetContent

func (req *OutboundAPIRequest) GetContent(data interface{}) error

GetContent ...

func (*OutboundAPIRequest) GetContentText

func (req *OutboundAPIRequest) GetContentText() string

GetContentText ...

func (*OutboundAPIRequest) GetHeaders

func (req *OutboundAPIRequest) GetHeaders() map[string]string

GetHeaders ...

func (*OutboundAPIRequest) GetIP

func (req *OutboundAPIRequest) GetIP() string

GetPath ..

func (*OutboundAPIRequest) GetMethod

func (req *OutboundAPIRequest) GetMethod() *MethodValue

GetMethod ..

func (*OutboundAPIRequest) GetParams

func (req *OutboundAPIRequest) GetParams() map[string]string

GetParams ...

func (*OutboundAPIRequest) GetPath

func (req *OutboundAPIRequest) GetPath() string

GetPath ..

type QueueItem

type QueueItem struct {
	Data            interface{}    `json:"data,omitempty" bson:"data,omitempty"`
	ID              *bson.ObjectId `json:"id,omitempty" bson:"_id,omitempty"`
	ProcessBy       string         `json:"processBy,omitempty" bson:"process_by,omitempty"`
	Version         string         `json:"version,omitempty" bson:"versionF,omitempty"`
	ProcessTimeMS   int            `json:"processTimeMS,omitempty" bson:"process_time_ms,omitempty"`
	CreatedTime     *time.Time     `json:"createdTime,omitempty" bson:"created_time,omitempty"`
	LastUpdatedTime *time.Time     `json:"lastUpdatedTime,omitempty" bson:"last_updated_time,omitempty"`
	LastFail        *time.Time     `json:"lastFail,omitempty" bson:"last_fail,omitempty"`
	Keys            *[]string      `json:"keys,omitempty" bson:"keys,omitempty"`
	Log             *[]string      `json:"log,omitempty" bson:"log,omitempty"`
}

type Request

type Request struct {
	Action string
	Data   interface{}
}

type RequestLogEntry

type RequestLogEntry struct {
	Status      string             `json:"status,omitempty" bson:"status,omitempty"`
	ReqURL      string             `json:"reqUrl,omitempty" bson:"req_url,omitempty"`
	ReqMethod   string             `json:"reqMethod,omitempty" bson:"req_method,omitempty"`
	ReqHeader   *map[string]string `json:"reqHeader,omitempty" bson:"req_header,omitempty"`
	ReqFormData *map[string]string `json:"reqFormData,omitempty" bson:"req_form_data,omitempty"`
	ReqBody     *interface{}       `json:"reqBody,omitempty" bson:"req_body,omitempty"`

	TotalTime  int64         `json:"totalTime,omitempty" bson:"total_time,omitempty"`
	RetryCount int           `json:"retryCount,omitempty" bson:"retry_count,omitempty"`
	Results    []*CallResult `json:"results,omitempty" bson:"results,omitempty"`
	ErrorLog   *string       `json:"errorLog,omitempty" bson:"error_log,omitempty"`
	Keys       *[]string     `json:"keys,omitempty" bson:"keys,omitempty"`
	Date       *time.Time    `bson:"date,omitempty" json:"date,omitempty"`
}

RequestLogEntry ...

type Response

type Response struct {
	Status  string
	Message string
	Data    interface{}
}

type RestClient

type RestClient struct {
	BaseURL   *url.URL
	UserAgent string
	// contains filtered or unexported fields
}

RestClient :

func NewHTTPClient

func NewHTTPClient(config *APIClientConfiguration) *RestClient

NewHTTPClient

func NewRESTClient

func NewRESTClient(baseURL string, logName string, timeout time.Duration, maxRetryTime int, waitTime time.Duration) *RestClient

NewRESTClient : New instance of restClient

func (*RestClient) MakeHTTPRequest

func (c *RestClient) MakeHTTPRequest(method HTTPMethod, headers map[string]string, params map[string]string, body interface{}, path string) (*RestResult, error)

MakeHTTPRequest :

func (*RestClient) MakeHTTPRequestWithKey

func (c *RestClient) MakeHTTPRequestWithKey(method HTTPMethod, headers map[string]string, params map[string]string, body interface{}, path string, keys *[]string) (*RestResult, error)

MakeHTTPRequestWithKey

func (*RestClient) MakeRequest

func (c *RestClient) MakeRequest(req OutboundAPIRequest) *APIResponse

MakeRequest ...

func (*RestClient) SetDBLog

func (c *RestClient) SetDBLog(dbName string, session *DBSession)

SetDBLog :

func (*RestClient) SetDebug

func (c *RestClient) SetDebug(val bool)

func (*RestClient) SetLoggerName

func (c *RestClient) SetLoggerName(loggerName string)

SetLoggerName :

func (*RestClient) SetMaxRetryTime

func (c *RestClient) SetMaxRetryTime(maxRetryTime int)

SetMaxRetryTime :

func (*RestClient) SetTimeout

func (c *RestClient) SetTimeout(timeout time.Duration)

SetTimeout :

func (*RestClient) SetWaitTime

func (c *RestClient) SetWaitTime(waitTime time.Duration)

SetWaitTime :

type RestResult

type RestResult struct {
	Body    string `json:"body,omitempty" bson:"body,omitempty"`
	Content []byte `json:"content,omitempty" bson:"content,omitempty"`
	Code    int    `json:"code,omitempty" bson:"code,omitempty"`
}

RestResult :

type Server

type Server struct {
	Poll        IPoll
	PollTimeout int64
	// contains filtered or unexported fields
}

func NewServer

func NewServer(kqTimeout int64) *Server

func (*Server) GetHandler

func (s *Server) GetHandler(path string) HandleFunc

func (*Server) Process

func (s *Server) Process(conn net.Conn)

func (*Server) SetHandle

func (s *Server) SetHandle(path string, handler HandleFunc)

func (*Server) Start

func (s *Server) Start()

type StatusEnum

type StatusEnum struct {
	Ok           string
	Error        string
	Invalid      string
	NotFound     string
	Forbidden    string
	Existed      string
	Unauthorized string
}

StatusEnum ...

type Task

type Task = func()

Task ...

type Worker added in v0.0.2

type Worker struct {
	Task Task
	// contains filtered or unexported fields
}

AppWorker ...

func (*Worker) Execute added in v0.0.2

func (worker *Worker) Execute()

Execute ...

func (*Worker) SetDelay added in v0.0.2

func (worker *Worker) SetDelay(seconds int) *Worker

SetDelay ...

func (*Worker) SetRepeatPeriod added in v0.0.2

func (worker *Worker) SetRepeatPeriod(seconds int) *Worker

SetRepeatPeriod ...

func (*Worker) SetTask added in v0.0.2

func (worker *Worker) SetTask(fn Task) *Worker

SetTask ..

Jump to

Keyboard shortcuts

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