gofmt wat u know about it
This commit is contained in:
parent
f93bdba75c
commit
89f95f2ac5
@ -2,7 +2,10 @@
|
||||
|
||||
package main
|
||||
|
||||
import ("fmt"; "errors")
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func myFun(arg int) (int, error) {
|
||||
if arg == 42 {
|
||||
|
@ -2,7 +2,10 @@
|
||||
|
||||
package main
|
||||
|
||||
import ("fmt" ; "sort")
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
)
|
||||
|
||||
type Person struct {
|
||||
Name string
|
||||
@ -10,6 +13,7 @@ type Person struct {
|
||||
}
|
||||
|
||||
type ByName []Person
|
||||
|
||||
func (this ByName) Len() int {
|
||||
return len(this)
|
||||
}
|
||||
@ -21,6 +25,7 @@ func (this ByName) Swap(i, j int) {
|
||||
}
|
||||
|
||||
type ByAge []Person
|
||||
|
||||
func (this ByAge) Len() int {
|
||||
return len(this)
|
||||
}
|
||||
|
@ -26,7 +26,9 @@ func main() {
|
||||
byt := []byte(`{"Name":"Wednesday","Age":6,"Parents":["Gomez","Morticia"]}`)
|
||||
var dat map[string]interface{}
|
||||
err := json.Unmarshal(byt, &dat)
|
||||
if err != nil { panic(err) }
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println(dat)
|
||||
|
||||
name := dat["Name"].(string)
|
||||
|
@ -13,5 +13,4 @@ func main() {
|
||||
fmt.Print(string(contents))
|
||||
}
|
||||
|
||||
|
||||
// todo: streaming reads
|
||||
|
@ -17,7 +17,6 @@ func main() {
|
||||
// with normal indexing.
|
||||
arg := os.Args[3]
|
||||
|
||||
|
||||
fmt.Println(argsWithProg)
|
||||
fmt.Println(argsWithoutProg)
|
||||
fmt.Println(arg)
|
||||
|
@ -2,7 +2,12 @@
|
||||
|
||||
package main
|
||||
|
||||
import ("fmt"; "os"; "os/signal"; "syscall")
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func main() {
|
||||
c := make(chan os.Signal, 1)
|
||||
|
@ -13,7 +13,9 @@ func main() {
|
||||
}
|
||||
client := &http.Client{Transport: tr}
|
||||
resp, err := client.Get("https://127.0.0.1:5000/")
|
||||
if err != nil { panic(err) }
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
body, _ := ioutil.ReadAll(resp.Body)
|
||||
fmt.Print(string(body))
|
||||
|
@ -15,10 +15,14 @@ func main() {
|
||||
|
||||
// set & get
|
||||
setRep := client.Set("foo", "bar")
|
||||
if setRep.Err != nil { panic(setRep.Err) }
|
||||
if setRep.Err != nil {
|
||||
panic(setRep.Err)
|
||||
}
|
||||
fmt.Println(setRep)
|
||||
getRep := client.Get("foo")
|
||||
if getRep.Err != nil { panic(getRep.Err) }
|
||||
if getRep.Err != nil {
|
||||
panic(getRep.Err)
|
||||
}
|
||||
getStr, _ := getRep.Str()
|
||||
fmt.Println(getRep)
|
||||
fmt.Println(getStr)
|
||||
@ -35,7 +39,9 @@ func main() {
|
||||
mc.Set("k1", "v1")
|
||||
mc.Get("k1")
|
||||
})
|
||||
if mcallRep.Err != nil { panic(mcallRep.Err) }
|
||||
if mcallRep.Err != nil {
|
||||
panic(mcallRep.Err)
|
||||
}
|
||||
mcallVal, _ := mcallRep.Elems[1].Str()
|
||||
fmt.Println(mcallVal)
|
||||
|
||||
@ -44,7 +50,9 @@ func main() {
|
||||
mc.Set("k2", "v2")
|
||||
mc.Get("k2")
|
||||
})
|
||||
if tranRep.Err != nil { panic(tranRep.Err) }
|
||||
if tranRep.Err != nil {
|
||||
panic(tranRep.Err)
|
||||
}
|
||||
tranStr, _ := tranRep.Elems[1].Str()
|
||||
fmt.Println(tranStr)
|
||||
|
||||
@ -53,7 +61,9 @@ func main() {
|
||||
fmt.Println(msg)
|
||||
}
|
||||
sub, subErr := client.Subscription(msgHdlr)
|
||||
if subErr != nil { panic(subErr) }
|
||||
if subErr != nil {
|
||||
panic(subErr)
|
||||
}
|
||||
defer sub.Close()
|
||||
sub.Subscribe("chan1", "chan2")
|
||||
sub.Psubscribe("chan*")
|
||||
|
@ -9,16 +9,22 @@ import "fmt"
|
||||
|
||||
func main() {
|
||||
db, openErr := sql.Open("postgres", "dbname=gobyexample sslmode=disable")
|
||||
if openErr != nil { panic(openErr) }
|
||||
if openErr != nil {
|
||||
panic(openErr)
|
||||
}
|
||||
defer db.Close()
|
||||
fmt.Println(db)
|
||||
|
||||
createRep, createErr := db.Exec("CREATE TABLE items (a int, b float, c boolean, d text, e timestamp with time zone)")
|
||||
if createErr != nil { panic(createErr) }
|
||||
if createErr != nil {
|
||||
panic(createErr)
|
||||
}
|
||||
fmt.Println(createRep)
|
||||
|
||||
insertRep, insertErr := db.Exec("INSERT INTO items VALUES (1, 2.0, false, 'string', '2000-01-01T01:02:03Z')")
|
||||
if insertErr != nil { panic(insertErr) }
|
||||
if insertErr != nil {
|
||||
panic(insertErr)
|
||||
}
|
||||
fmt.Println(insertRep)
|
||||
|
||||
t1, _ := time.Parse(time.RFC3339, "2000-04-08T03:02:01Z")
|
||||
@ -26,12 +32,16 @@ func main() {
|
||||
minsertRep, minsertErr := db.Exec("Insert INTO items VALUES ($1, $2, $3, $4, $5), ($6, $7, $8, $9, $10)",
|
||||
3, 7.0, true, "more", t1,
|
||||
5, 1.0, false, "less", t2)
|
||||
if minsertErr != nil { panic(minsertErr) }
|
||||
if minsertErr != nil {
|
||||
panic(minsertErr)
|
||||
}
|
||||
num, _ := minsertRep.RowsAffected()
|
||||
fmt.Println(num)
|
||||
|
||||
rows, selectErr := db.Query("SELECT * FROM items")
|
||||
if selectErr != nil { panic(selectErr) }
|
||||
if selectErr != nil {
|
||||
panic(selectErr)
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var r1 int
|
||||
@ -43,10 +53,14 @@ func main() {
|
||||
fmt.Println(r1, r2, r3, r4, r5)
|
||||
}
|
||||
rowsErr := rows.Err()
|
||||
if rowsErr != nil { panic(rowsErr) }
|
||||
if rowsErr != nil {
|
||||
panic(rowsErr)
|
||||
}
|
||||
|
||||
dropRep, dropErr := db.Exec("DROP TABLE items")
|
||||
if dropErr != nil { panic(dropErr) }
|
||||
if dropErr != nil {
|
||||
panic(dropErr)
|
||||
}
|
||||
fmt.Println(dropRep)
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,9 @@ func main() {
|
||||
[]string{"mark@heroku.com"},
|
||||
[]byte("nThe body."),
|
||||
)
|
||||
if err != nil { panic(err) }
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// todo: missing subject, cc, bcc
|
||||
|
@ -3,10 +3,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"encoding/base64"
|
||||
"strings"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Authenticator func(string, string) bool
|
||||
|
@ -3,14 +3,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"time"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"fmt"
|
||||
"sync/atomic"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
func slow(res http.ResponseWriter, req *http.Request) {
|
||||
@ -52,7 +52,9 @@ func main() {
|
||||
server := &http.Server{Handler: http.HandlerFunc(slow)}
|
||||
fmt.Println("listen at=start")
|
||||
listener, listenErr := net.Listen("tcp", ":5000")
|
||||
if listenErr != nil { panic(listenErr) }
|
||||
if listenErr != nil {
|
||||
panic(listenErr)
|
||||
}
|
||||
wListener := &watchedListener{Listener: listener}
|
||||
fmt.Println("listen at=finish")
|
||||
|
||||
@ -60,7 +62,9 @@ func main() {
|
||||
<-stop
|
||||
fmt.Println("close at=start")
|
||||
closeErr := wListener.Close()
|
||||
if closeErr != nil { panic(closeErr) }
|
||||
if closeErr != nil {
|
||||
panic(closeErr)
|
||||
}
|
||||
fmt.Println("close at=finish")
|
||||
}()
|
||||
|
||||
|
@ -12,5 +12,7 @@ func handler(res http.ResponseWriter, req *http.Request) {
|
||||
func main() {
|
||||
http.HandleFunc("/", handler)
|
||||
err := http.ListenAndServeTLS(":5000", "/tmp/server.crt", "/tmp/server.key", nil)
|
||||
if err != nil { panic(err) }
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
@ -6,14 +6,14 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"regexp"
|
||||
"os"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func minInt(a, b int) int {
|
||||
if (a < b) {
|
||||
if a < b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
@ -24,7 +24,9 @@ func main() {
|
||||
sourceNames := make([]string, 0)
|
||||
sourceMap := make(map[string]string)
|
||||
fileInfos, dirErr := ioutil.ReadDir("./")
|
||||
if dirErr != nil { panic(dirErr) }
|
||||
if dirErr != nil {
|
||||
panic(dirErr)
|
||||
}
|
||||
baseTrimmer, _ := regexp.Compile("[0-9x]+-")
|
||||
for _, fi := range fileInfos {
|
||||
baseName := baseTrimmer.ReplaceAllString(fi.Name(), "")
|
||||
@ -36,7 +38,9 @@ func main() {
|
||||
|
||||
// read names from index
|
||||
indexBytes, idxErr := ioutil.ReadFile("tool/index.txt")
|
||||
if idxErr != nil { panic (idxErr) }
|
||||
if idxErr != nil {
|
||||
panic(idxErr)
|
||||
}
|
||||
indexNamesAll := strings.Split(string(indexBytes), "\n")
|
||||
indexNames := make([]string, 0)
|
||||
for _, indexName := range indexNamesAll {
|
||||
|
Loading…
x
Reference in New Issue
Block a user