随笔分类 - golibs
摘要:```go
package main import ( "log" "net" "net/rpc" "net/rpc/jsonrpc"
) type Args struct { A, B int
} type Result int type RpcServer struct{} func (t RpcServer) Add(args *Args, result *Result)...
阅读全文
摘要:```go package main import ( "crypto/tls" "fmt" "net/smtp"
) func main() { var email string fmt.Println("Enter username for smtp: ") fmt.Scanln(&email) var pass string fmt.Println("Enter p...
阅读全文
摘要:```go package main import ( "encoding/json" "fmt" "io" "io/ioutil" "net/http" "strconv" "strings" ) const addr = "localhost:7070" type City struct { I
阅读全文
摘要:```go package main import ( "fmt" "net/http"
) const addr = "localhost:7070" type RedirecServer struct { redirectCount int
} func (s *RedirecServer) ServeHTTP(rw http.ResponseWriter, req *htt...
阅读全文
摘要:```go package main import ( "fmt" "net/http"
) func main() { header := http.Header{} // Using the header as slice header.Set("Auth-X", "abcdef1234") header.Add("Auth-X", "defghijkl") fmt.P...
阅读全文
摘要:```go package main import ( "fmt" "io/ioutil" "net/http" "net/url" "strings"
) type StringServer string func (s StringServer) ServeHTTP(rw http.ResponseWriter, req *http.Request) { req.Parse...
阅读全文
摘要:```go
package main import ( "encoding/json" "fmt" "net/url"
) func main() { u := &url.URL{} u.Scheme = "http" u.Host = "localhost:80" u.Path = "index.html" u.RawQuery = "id=1&name=John" u....
阅读全文
摘要:```go package main import ( "fmt" "io/ioutil" "net/http" "net/url" "strings"
) type StringServer string func (s StringServer) ServeHTTP(rw http.ResponseWriter, req *http.Request) { req.Parse...
阅读全文
摘要:```go package main import ( "fmt" "net"
) func main() { // Resolve by IP addrs, err := net.LookupAddr("127.0.0.1") if err != nil { panic(err) } for _, addr := range addrs { fmt.Println...
阅读全文
摘要:```go package main import ( "bufio" "context" "fmt" "io" "net" "net/http" "time"
) type StringServer string func (s StringServer) ServeHTTP(rw http.ResponseWriter, req *http.Request) { rw....
阅读全文
摘要:```go package main import ( "fmt" "net"
) func main() { // Get all network interfaces interfaces, err := net.Interfaces() if err != nil { panic(err) } for _, interf := range interfaces ...
阅读全文
摘要:```go package main import ( "fmt" "log" "os/user"
) func main() { usr, err := user.Current() if err != nil { log.Fatal(err) } fmt.Println("The user home directory: " + usr.HomeDir)
} /*...
阅读全文
摘要:```go package main import ( "bufio" "crypto/md5" "fmt" "io" "os"
) var data = []struct { name string cont string perm os.FileMode
}{ {"test1.file", "Hello\nGolang is great", 0666}, {"test...
阅读全文
摘要:```go package main import ( "fmt" "os" "path/filepath" ) func main() { for i := 1; i
阅读全文
摘要:```go package main import ( "os"
) func main() { f, err := os.Create("created.file") if err != nil { panic(err) } f.Close() f, err = os.OpenFile("created.byopen", os.O_CREATE|os.O_APPEND,...
阅读全文
摘要:```go package main import ( "fmt" "os"
) func main() { f, err := os.Create("test.file") if err != nil { panic(err) } defer f.Close() // Obtain current permissions fi, err := f.Stat() ...
阅读全文
摘要:```go package main import ( "fmt" "io/ioutil" "os" "path/filepath"
) func main() { fmt.Println("List by ReadDir") listDirByReadDir(".") fmt.Println() fmt.Println("List by Walk") listDirBy...
阅读全文
摘要:```go package main import ( "fmt" "io" "os" "sync"
) type SyncWriter struct { m sync.Mutex Writer io.Writer
} func (w *SyncWriter) Write(b []byte) (n int, err error) { w.m.Lock() defe...
阅读全文
摘要:```go package main import ( "io" "os" "strings"
) func main() { f, err := os.Create("sample.file") if err != nil { panic(err) } defer f.Close() _, err = f.WriteString("Go is awesome!\n...
阅读全文
摘要:```go package main import "io/ioutil"
import "os"
import "fmt" func main() { tFile, err := ioutil.TempFile("", "gostdcookbook") if err != nil { panic(err) } // The called is responsible for h...
阅读全文

浙公网安备 33010602011771号