// note - arrays are of FIXED size, while slices can be modified
////////// MAPS --- probably most used as we can use a string as an index instead of just integers
newmap := make(map[string]string) // make a map of STRINGS
newmap["lomas"] = "bbq"
newmap["horse"] = "handsome"
fmt.Println(newmap)
delete(newmap("horse")
/////////// slices
// init slice
var slice = make([]string, 2) // make an array with 2 elements (0 and 1)
// add item to slice
slice[0] = "how are you?"
// append or add an item to slice
slice = append(slice, "how are you?")
// append multiple items
slice = append(array, "how", "are", "you", "?")
// delete item 2 from slice
slice = append(slice[:2], slice[2+1:]...) // note, only change the 2
// copy element to another slice
newslice := make([]string, 3) // this must be big enough to fit all the elements in
copy(newslice, slice)
fmt.Println(newslice)
/////////// arrays - only used if we know the size, we cannot change it once initialised
// init array
var array [2]string // make an array of strings with 2 items (0 and 1)
// add items to array
array[0] = "how are you?"
// output array OR slice
fmt.Println(array) // dump whole array
fmt.Print(array[0]) // output single item
json [Golang] golang #golang #snippets中有用的片段
[ fmt ](https://golang.org/pkg/fmt/)
-------
Print any `type`(struct,maps,primitives) with the `key` name
```
fmt.Printf("\n [key] :%+v \n", [value])
```
Print Error
```
fmt.Errorf(" \nError: %s", err.Error())
```
[ log ](https://golang.org/pkg/log/)
-------------
Print any `type`(struct,maps,primitives) with the `key` name
```
log.Printf("\n [key] :%+v \n", [value])
```
[ http ](https://golang.org/pkg/log/)
-------------
http middleware
```
func [middlewareName](h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Do things before request
nextMiddleware.ServeHTTP(w, r)
// Do things after request
})
}
```