goutils

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2021 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 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
	//
	conf, err := goutils.GetConf("test.conf")
	if nil != err {
		return
	}
	fmt.Println(conf)
}
Output:
{ foo: ["bar"], foos: ["1", "2"], null: [] }

func GetOptions

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

解析命令行参数

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{})

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 Option

type Option struct {
	Opt       byte
	Option    string
	HasParams bool
}

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)

发送

Directories

Path Synopsis
totp module

Jump to

Keyboard shortcuts

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