sanjib / fun-with-go

A personal journey of fun and experiments with the Go language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

fun-with-go

A personal journey of fun and experiments with the Go language.

Following are some of the functions, variables and commands that I am personally using along my journey with Go.

functions and vars

  • len(v Type) int
  • bufio.NewScanner(r io.Reader) *Scanner
  • bufio: (s *Scanner).Scan() bool
  • bufio: (s *Scanner).Text() string
  • fmt.Println(a ...interface{}) (n int, err error)
  • fmt.Sprintf(format string, a ...interface{}) string
  • strings.Join(elems []string, sep string) string
  • os.Args []string
  • os.Stdin NewFile(uintptr(syscall.Stdin), "/dev/stdin")
  • runtime.NumCPU() int
  • time.Now() Time
  • time.Since(t Time) Duration

keywords

  • break
  • case
  • chan
  • const // example: const World = "世界"
  • default
  • defer
  • else
  • for
  • func
  • go
  • if
  • import
  • interface
  • map
  • package
  • range
  • return
  • select
  • struct
  • switch
  • type // example: switch v := i.(type)
  • var

keywords pool

  • goto
  • fallthrough
  • continue

tools

  • go [command] [arguments]
  • go build [packages]
  • go doc [pkg] [methodOrField]
  • go fmt [filename]
  • go get [packages] (-v:verbose)
  • go help [keyword]
  • go run [filename]
  • go test -bench=. [filename]
  • go version

definitions

  • pointers
    • a pointer holds the memory address of a value
    • the & operator generates a pointer to its operand
    • the * operator denotes a pointer's underlying value

some common conversion characters in format strings

%d int in decimal
%x, %o, %b int in hex, oct, bin
%f, %g, %e float
%t bool
%c rune
%s string
%q quoted string, rune
%v any value
%T type
%% literal percent

helpful custom programs

nuances

type Stringer interface {
    String() string
}
type error interface {
    Error() string
}
  • there are many implementations of the io.Reader interface, including files, network connections, compressors, ciphers, and others

exercise solutions

ref blog articles

About

A personal journey of fun and experiments with the Go language


Languages

Language:Go 97.1%Language:HTML 2.4%Language:JavaScript 0.3%Language:CSS 0.1%