Back to

Package common

Latest Go to latest

The latest major version is .

Published: Mar 27, 2020 | License: MIT | Module:



const (
	// DefaultFormat default time format
	DefaultFormat = "2006-01-02 15:04:05"

func CacheJob

func CacheJob(cache map[string]interface{}) error

CacheJob store job

func CacheNews

func CacheNews(path string)

CacheNews save to db

func GenerateKey

func GenerateKey(data int64, length int) string

GenerateKey return string which has 0 prefix for number 25 and length equals 6 => 000025

func GetFileList

func GetFileList(dir string) []string

GetFileList read directory path and return file list

func GetJob

func GetJob(id string) (map[string]string, error)

GetJob get job

func GetNewsCache

func GetNewsCache(key string) (map[string]string, error)

GetNewsCache 获取新闻缓存

func GetPagedNews

func GetPagedNews(pageNum int64, pageSize int64) ([]map[string]string, int64, error)

GetPagedNews 获取新闻

func GinLogger

func GinLogger(log *logrus.Logger) gin.HandlerFunc

GinLogger 基于logrus 的log中间件

func InitDataPuller

func InitDataPuller(config *Config) error

InitDataPuller load data from file and save into redis dir E:/tmp/data repo

func InitEnv

func InitEnv(config *Config)

InitEnv init env variable

func LoggerFromConfig

func LoggerFromConfig(config *Config) *logrus.Logger

LoggerFromConfig get logger by filename

func ParseData

func ParseData(data string, length int) (string, string)

ParseData return two strings for string 202002020004 and length equals 8 => 20200202, 0004

func SetNewsToCache

func SetNewsToCache(cache map[string]interface{}) error

SetNewsToCache store data to redis

func StartServ

func StartServ(config *Config)

StartServ start server at 8080

type Common

type Common struct {
	DataFolder string `ini:"dataFolder"`
	Repo       string `ini:"repo"`

Common config

type Config

type Config struct {
	Common `ini:"common"`
	Server `ini:"server"`
	Redis  `ini:"redis"`
	Log    `ini:"log"`

Config config

func InitConfig

func InitConfig(configFileMame string) (*Config, error)

InitConfig read config from file

type Job

type Job struct {
	ID     string
	Status string
	Err    error

Job async job

func NewJob

func NewJob() *Job

NewJob job constructure

func (*Job) CacheJob

func (j *Job) CacheJob() (string, error)

CacheJob store job to db

func (*Job) GetCacheJob

func (j *Job) GetCacheJob() error

GetCacheJob get job from db

func (*Job) GetStatus

func (j *Job) GetStatus() (string, error)

GetStatus get job status

func (*Job) SetErr

func (j *Job) SetErr(err error)

SetErr set job err

func (*Job) SetFinish

func (j *Job) SetFinish()

SetFinish set job finish

type Log

type Log struct {
	LogFilePath string `ini:"logFilePath"`
	LogFileName string `ini:"logFileName"`
	LogLevel    int    `ini:"logLevel"`
	LogOutput   string `ini:"logOutput"`

Server config

type News

type News struct {
	ID    int64
	Title string
	Link  url.URL
	Ctime time.Time

News news structure

func ParseNews

func ParseNews(path string) (newsList []News, err error)

ParseNews get news from file and return news list

type Redis

type Redis struct {
	Host         string `ini:"host"`
	DB           int    `ini:"db"`
	CachePrefix  string `ini:"cachePrefix"`
	SortedPrefix string `ini:"sortedPrefix"`

Redis config

type Server

type Server struct {
	Port       int    `ini:"port"`
	Mode       string `ini:"mode"`
	StaticPath string `ini:"staticPath"`

Server config

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier