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