This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func write(localFile, remoteFile string) (err error) { | |
buf := bytes.NewBuffer([]byte{}) | |
mw := multipart.NewWriter(buf) | |
if err = mw.WriteField("field", value); err != nil { | |
return | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type SorterDefault []MyType | |
func (s SorterDefault) Len() int { return len(s)} | |
func (s SorterDefault) Swap(i, j int) { s[i], s[j] = s[j], s[i]} | |
type Sorter1 struct { SorterDefault } | |
func (s Sorter1) Less(i, j int) bool { ... } | |
type Sorter2 struct { SorterDefault } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*cgopkg.go*/ | |
package cgopkg | |
//#include <stdlib.h> | |
//#include "cgopkg.h" | |
import "C" | |
import ( | |
"unsafe" | |
) | |
func Foo() { | |
chi := C.CString("hi") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func Redirect(wr io.Writer, data interface{}) { | |
switch data.(type) { | |
case ElementA: | |
templateA.Execute(wr, data) | |
case ElementB: | |
templateB.Execute(wr, data) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{range .Stuff}} | |
{{if .(ElementA)}}string:{{.X}} int:{{.Y}}{{end}} | |
{{if .(ElementB)}}int:{{.X}} string:{{.Y}}{{end}} | |
{{end}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
loop: | |
for { | |
select { | |
case <-me.stopChan: | |
break loop | |
default: | |
compute() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
type MySlice []int | |
func main() { | |
s := MySlice{1,2,3,4} | |
for i, v := range s { | |
fmt.Println(i, v) |
NewerOlder