Skip to content

Instantly share code, notes, and snippets.

View tomtsang's full-sized avatar

tomtsang tomtsang

  • ttechnology
  • china
View GitHub Profile
@tomtsang
tomtsang / apikeys.json
Last active June 11, 2022 09:14
apikeys.json
["jaagtngoNITvjOeYiy6BDmmAYhlESfZyqJkUuBXXSQA5WujPj0IIeEps0SK3Xdll", "X1g7kCCV1P84RItaLXXRHtUCBQ3udJX4jSOAUjYGwRmq7T4QhMGsRcSFEo6AuUrT", "kPRtbrEKuCWzEADQcuCFfQK03YNHVLNO4oWZ5IH2fy3uQq7OSbHchn4ln91g5TLL"]
@tomtsang
tomtsang / assign.go
Created February 16, 2018 01:38
assign.go
package main
import (
"fmt"
)
func main() {
power := 1000
fmt.Printf("default power is %d\n", power)
@tomtsang
tomtsang / slice-copy.go
Created February 14, 2018 06:01
slice-copy.go
package main
import (
"fmt"
)
func main() {
sliceA := []string{"a", "b", "c"}
fmt.Println(sliceA)
sliceB := []string{"k", "l", "m", "n"}
@tomtsang
tomtsang / slice-2.go
Created February 14, 2018 05:56
slice-2.go
package main
import (
"fmt"
)
func main() {
array1 := [...]string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"}
slice1 := array1[2:6]
fmt.Println(slice1)
@tomtsang
tomtsang / slice-append.go
Last active February 14, 2018 03:33
slice append change the array data
package main
import (
"fmt"
)
func main() {
array1 := [...]string{"a", "b", "c", "d", "e", "f"}
slice1 := array1[:4]
fmt.Println(slice1)
@tomtsang
tomtsang / func-call-order.go
Created February 14, 2018 03:27
function call order
package main
import (
"fmt"
)
func main() {
a := 10
f := func() int { a = a * 2; return 5 }
x := []int{a, f()}
@tomtsang
tomtsang / error-type.go
Created February 11, 2018 14:56
error-type.go
type SyntaxError struct {
msg string // description of error
// error occurred after reading Offset bytes, from which line and columnnr can be obtained
Offset int64
}
func (e *SyntaxError) String() string { return e.msg }
if serr, ok := err.(*json.SyntaxError); ok {
@tomtsang
tomtsang / path-error.go
Created February 11, 2018 14:54
path-error.go
// PathError records an error and the operation and file path that caused it.
type PathError struct {
Op string // "open", "unlink", etc.
Path string // The associated file.
Err error // Returned by the system call.
}
func (e *PathError) String() string {
return e.Op + " " + e.Path + ": "+ e.Err.Error()
}
@tomtsang
tomtsang / golang-interface-methodset.go
Created February 11, 2018 02:27
golang-interface-methodset.go
package main
import (
"fmt"
)
type List []int
// 值的方法
func (l List) Len() int {
@tomtsang
tomtsang / struct-anonymous-method.go
Created February 10, 2018 08:07
struct-anonymous-method.go
package main
import (
"fmt"
"math"
)
type Point struct {
x, y float64
}