Go语言中文网 为您找到相关结果 18

golang 异或加解密

func XorEncodeStr(msg, key string) string { ml := len(msg) kl := len(key) pwd := "" for i := 0; i < ml; i++ { pwd += (string((key[i%kl]) ^ (msg[i]))) } return pwd}func XorDecodeStr(msg, key string) string { ml := len(msg) kl := len(key) pwd := "" for i := 0; i < ml; i++ { pwd += (string(((msg[i]) ^ key[i%kl]))) } return pwd} 使用方法,传入msg和key即可,开始百度了很...阅读全文

博文 2019-04-30 09:34:41 许成志

关于martini 一点不解之处

今天在看martini的源码,其中有这个函数: ```go func (m *Martini) RunOnAddr(addr string) { logger := m.Injector.Get(reflect.TypeOf(m.logger)).Interface().(*log.Logger) logger.Printf("listening on %s (%s)\n", addr, Env) logger.Fatalln(http.ListenAndServe(addr, m)) } ``` 里面获取logger的方式为什么不用m.logger,非要采用Injector方式,是性能的原因吗?请大家指...阅读全文

Go菜鸟关于switch问题求指点!

菜鸟求教,一个简单无限循环代码,但为什么输入bye,却无法结束呢? package main import( "bufio" "fmt" "os" "strings" ) func main(){ inputReader := bufio.NewReader(os.Stdin) fmt.Println("Please input your name:") input,err := inputReader.ReadString('\n') if err!=nil{ fmt.Printf("An error occurred :%s\n", err) os.Exit(1) }else{ name := inp...阅读全文

conn.(*dbConnection).ID 括号中的这种用户没懂,请指点

```go // performQueries tests the resource pool of connections. func performQueries(query int, p *pool.Pool) { // Acquire a connection from the pool. conn, err := p.Acquire() if err != nil { log.Println(err) return } // Release the connection back to the pool. defer p.Release(conn) // Wait to simulate a query response. ti...阅读全文

关于文本读取的问题

func readMaze(fileName string) [][]int{ file, err := os.Open(fileName) if err != nil{ panic(err) } var row, col int fmt.Fscanf(file, "%d %d", &row, &col) maze := make([][]int, row) for i := range maze { maze[i] = make([]int, col) for j := range maze[i] { fmt.Fscanf(file, "%d", &maze[i][j]) } } return maze } func main() { maze := readMaze("src/maze/...阅读全文

博文 2018-09-17 17:34:59 Mosan