goutils

package module
v0.1.22 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2025 License: LGPL-3.0 Imports: 19 Imported by: 11

Documentation

Index

Examples

Constants

View Source
const (
	TLSFLAG_IGNORE = 0 // 000
	TLSFLAG_CLIENT = 1 // 001
	TLSFLAG_SERVER = 2 // 010
	TLSFLAG_VERIFY = 3 // 011
)

Variables

This section is empty.

Functions

func DecodeBase64 added in v0.1.7

func DecodeBase64(msg string) (string, error)

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 GenTlsConfig added in v0.1.16

func GenTlsConfig(flag TlsFlag, crt, key, ca string) (*tls.Config, error)

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 ListenAndHttp added in v0.1.8

func ListenAndHttp(network, addr, crt, key string, handler http.Handler)

func LoadCryptoObj added in v0.1.15

func LoadCryptoObj(crt, key, ca string) ([]tls.Certificate, *x509.CertPool, error)

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 QuicDial added in v0.1.14

func QuicDial(network, crt, key, ca string, cfg *quic.Config, ignore bool) (quic.Connection, error)

func QuicListenAddr added in v0.1.14

func QuicListenAddr(network, crt, key, ca string, cfg *quic.Config, verifyClient bool) (*quic.Listener, error)

func Random

func Random() float64

func RandomString

func RandomString(length int) string

func ReadLineN

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

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

func SHA1 added in v0.1.10

func SHA1(src string) string

func ServeHttp added in v0.1.8

func ServeHttp(cfg *ListenOptions, handler http.Handler)

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 Conf added in v0.1.22

type Conf map[string][]string

func GetConf

func GetConf(filename string) (Conf, error)

read configure file

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 (*Conf) GetVal added in v0.1.22

func (conf *Conf) GetVal(key string) string

type ListenOptions added in v0.1.9

type ListenOptions struct {
	Unix   string
	Tcp    string
	TcpLts string
	Quic   string
	Crt    string
	Key    string
}

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 (st *Stream) End(content string)

发送并关闭

func (*Stream) ReadLine

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

func (*Stream) Send

func (st *Stream) Send(content string)

发送

type TlsFlag added in v0.1.16

type TlsFlag int

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