Skip to content

Instantly share code, notes, and snippets.

@lamarmarshall
lamarmarshall / selectchan.go
Created October 26, 2017 22:37
go thread select chan
package main
import (
"fmt"
"time"
)
func main() {
// first chan to return executes
select {
@lamarmarshall
lamarmarshall / structoop2.go
Created October 26, 2017 23:13
go struct oop
package main
import (
"fmt"
)
type Person struct {
age int
}
@lamarmarshall
lamarmarshall / constructor.go
Created October 26, 2017 23:21
struct oop constructor
package main
import (
"fmt"
)
type Person struct {
age int
}
@lamarmarshall
lamarmarshall / generics.go
Last active October 26, 2017 23:47
generic function arguments, interface arguments
package main
import (
"fmt"
)
func whatami(tp interface{}) {
switch tp.(type) {
case int:
@lamarmarshall
lamarmarshall / anon.go
Created October 27, 2017 14:01
anonymous struct
package main
import (
"fmt"
)
func main() {
king := struct {
name string
@lamarmarshall
lamarmarshall / json.go
Created November 1, 2017 14:30
go json
package main
import (
"fmt"
"encoding/json"
)
// all field names must start with capital letters
type person struct {
Name string `json:"name"`
Age int `json:"age"`
@lamarmarshall
lamarmarshall / serveu.go
Created November 1, 2017 14:30
go http server
package server
import (
"fmt"
"log"
"net/http"
)
func root(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "hello world")
@lamarmarshall
lamarmarshall / req.js
Created November 1, 2017 17:39
node request http
rconst req = require('request')
req({
url: "https://api.coinmarketcap.com/v1/ticker/",
json: true
},
( err, resp, body) => {
console.log(body[0].name)
})
@lamarmarshall
lamarmarshall / gormtest.go
Created November 5, 2017 13:41
gorm orm for go
package main
import (
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/sqlite"
)
//Person - defines person table
type Person struct {
gorm.Model
@lamarmarshall
lamarmarshall / gomysql.go
Created November 5, 2017 13:42
go mysql
package main
import (
"database/sql"
"fmt"
"log"
_ "github.com/go-sql-driver/mysql"
)