Documentation
¶
Index ¶
- func EncodeBase64(msg string) string
- func Errorf(format string, v ...interface{})
- func GetConf(filename string) (map[string][]string, error)
- func GetOptions(options []Option) (map[string]string, []string)
- func MD5(src string) string
- func Now() int64
- func NowNano() uint64
- func Printf(format string, v ...interface{})
- func Random() float64
- func RandomString(length int) string
- func ReadLineN(filename string, n int) ([]string, error)
- func Socket(port string) (net.Listener, error)
- func TLSSocket(port string, crt string, key string) (net.Listener, error)
- type Option
- type Stream
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EncodeBase64 ¶
func GetConf ¶
读取配置文件
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 ¶
解析命令行参数
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)
}
Output:
func RandomString ¶
Types ¶
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
func InitStream ¶
func InitStream(sock io.ReadWriteCloser) *Stream
Click to show internal directories.
Click to hide internal directories.