Skip to content

Instantly share code, notes, and snippets.

@mottet-dev
mottet-dev / slices.go
Last active July 8, 2019 20:10
Go Test - SliceIncludesInt
package helpers
func DoesSliceIncludesInt(value int, slice []int) bool {
for _, i := range slice {
if value == i {
return true
}
}
return false
}
@mottet-dev
mottet-dev / ingredient.go
Created June 30, 2019 16:32
Gorilla Mux - Ingredients
package model
type Ingredient struct {
ID int `json:"id"`
Name string `json:"name"`
Price float32 `json:"price"`
Quantity int `json:"quantity"`
Unit string `json:"unit"`
}
@mottet-dev
mottet-dev / main.go
Created June 23, 2019 16:08
Go Funk - Contains
package main
import (
"fmt"
"github.com/thoas/go-funk"
)
func main() {
result := funk.Contains([]int{1, 2, 3, 4, 5}, 3)
@mottet-dev
mottet-dev / main.go
Created June 20, 2019 20:33
Go Funk - Reduce
package main
import (
"fmt"
"github.com/thoas/go-funk"
)
func main() {
baseSlice := []int{1, 2, 3, 4, 5}
sum := funk.Reduce(baseSlice, func(acc, elem int) int { return acc + elem }, 0)
@mottet-dev
mottet-dev / main.go
Created June 20, 2019 20:23
Go Funk - Filter
package main
import (
"fmt"
"github.com/thoas/go-funk"
)
func main() {
baseSlice := []int{1, 2, 3, 4, 5}
newSlice := funk.Filter(baseSlice, func(x int) bool {
@mottet-dev
mottet-dev / main.go
Created June 20, 2019 20:09
Go Funk - Map - Type assertion
package main
import (
"fmt"
"github.com/thoas/go-funk"
)
func main() {
baseSlice := []int{1, 2, 3, 4, 5}
newSlice := funk.Map(baseSlice, func(x int) int {
@mottet-dev
mottet-dev / main.go
Created June 20, 2019 20:00
Go Funk - Map
package main
import (
"fmt"
"github.com/thoas/go-funk"
)
func main() {
baseSlice := []int{1, 2, 3, 4, 5}
newSlice := funk.Map(baseSlice, func(x int) int {
@mottet-dev
mottet-dev / main.go
Created June 20, 2019 19:48
Go funk - Contains signature
func Contains(in interface{}, elem interface{}) bool
@mottet-dev
mottet-dev / main.go
Created June 15, 2019 16:21
User Agent Print - Go Colly
fmt.Println("UserAgent", r.Headers.Get("User-Agent"))
@mottet-dev
mottet-dev / main.go
Created June 15, 2019 16:18
User Agent - Go Colly
extensions.RandomUserAgent(c)