goutils

package module
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2022 License: LGPL-3.0 Imports: 12 Imported by: 11

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeBase64

func EncodeBase64(msg string) string

func Errorf

func Errorf(format string, v ...interface{})

func GenHelp added in v0.1.5

func GenHelp(options []Option, desc string) string

func GetConf

func GetConf(filename string) (map[string][]string, error)

读取配置文件

Example
package main

import (
	"fmt"
	"github.com/watsonserve/goutils"
)

func main() {
	// # test.conf
	// # this is a config file
	// foo = bar
	// foos=1
	// foos = 2
	// null
	//
	link := goutils.NewList(nil)
	link.Mount(20, 80)
	fmt.Println(link.ToArray())
}
Example
package main

import (
	"fmt"
	"github.com/watsonserve/goutils"
)

func main() {
	// # test.conf
	// # this is a config file
	// foo = bar
	// foos=1
	// foos = 2
	// null
	//
	conf, err := goutils.GetConf("test.conf")
	if nil != err {
		return
	}
	fmt.Println(conf)
}
Output:
map[foo:[bar] foos:[1 2] null:[]]

func GetOptions

func GetOptions(options []Option) (map[string]string, []string)

parse commandline params

Example
package main

import (
	"fmt"
	"github.com/watsonserve/goutils"
)

func main() {
	options := []goutils.Option{
		{
			Opt:       'h',
			Option:    "help",
			HasParams: false,
		},
		{
			Opt:       'z',
			Option:    "gz",
			HasParams: false,
		},
		{
			Opt:       'C',
			Option:    "cc",
			HasParams: true,
		},
		{
			Opt:       'f',
			Option:    "file",
			HasParams: true,
		},
	}
	argMap, params := goutils.GetOptions(options)

	fmt.Println(argMap)
	fmt.Println(params)
}

func MD5

func MD5(src string) string

func Now

func Now() int64

func NowNano

func NowNano() uint64

func Printf

func Printf(format string, v ...interface{})
Example
package main

import (
	"github.com/watsonserve/goutils"
)

func main() {
	goutils.Printf("- %d -\n", 404)
}

func Random

func Random() float64

func RandomString

func RandomString(length int) string

func ReadLineN

func ReadLineN(filename string, n int) ([]string, error)

从一个文件中读取前n行和后面所有内容

func Socket

func Socket(port string) (net.Listener, error)

* 这里使用的是每个链接启动一个新的go程的模型 * 高并发的话,性能取决于go语言的协程能力

func TLSSocket

func TLSSocket(port string, crt string, key string) (net.Listener, error)

* 这里使用的是每个链接启动一个新的go程的模型 * 高并发的话,性能取决于go语言的协程能力

Types

type Any_t added in v0.1.3

type Any_t interface{}

type Option

type Option struct {
	Name      string
	Opt       byte
	Option    string
	HasParams bool
	Desc      string
}

type Pool_t added in v0.1.3

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

func NewPool added in v0.1.3

func NewPool(workerInit WorkerGenerator, size int) *Pool_t

func (*Pool_t) Count added in v0.1.3

func (pool *Pool_t) Count() int

func (*Pool_t) Push added in v0.1.3

func (pool *Pool_t) Push(foo Any_t)

func (*Pool_t) Wait added in v0.1.3

func (pool *Pool_t) Wait() Any_t
type RangeLink_t struct {
	// contains filtered or unexported fields
}
func NewRangeLink(arr []Range_t) *RangeLink_t
func (this *RangeLink_t) Append(newNode *RangeNode_t)

尾添加

func (this *RangeLink_t) Converse(start int64, end int64) *RangeLink_t

取反

func (this *RangeLink_t) Front() *Range_t

头查看

func (this *RangeLink_t) Mount(start int64, end int64)

挂载

func (this *RangeLink_t) Pop()

头删除

func (this *RangeLink_t) Push(newNode *RangeNode_t)

头添加

func (this *RangeLink_t) ToArray() []Range_t

转成数组

type RangeNode_t added in v0.1.2

type RangeNode_t struct {
	Range_t
	Next *RangeNode_t
}

type Range_t added in v0.1.2

type Range_t struct {
	Start int64
	End   int64
}

type Stream

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

func InitStream

func InitStream(sock io.ReadWriteCloser) *Stream

func (*Stream) End

func (this *Stream) End(content string)

发送并关闭

func (*Stream) ReadLine

func (this *Stream) ReadLine() (string, error)

func (*Stream) Send

func (this *Stream) Send(content string)

发送

type Worker added in v0.1.4

type Worker interface {
	Work(params Any_t) Any_t
	Destroy()
}

type WorkerGenerator added in v0.1.4

type WorkerGenerator func() (Worker, error)

Directories

Path Synopsis
totp module

Jump to

Keyboard shortcuts

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