Skip to content

Instantly share code, notes, and snippets.

@chadlung
chadlung / main.go
Last active February 13, 2020 22:34
An example Go (golang) REST service that uses JWT (JSON Web Tokens) and Negroni http://www.giantflyingsaucer.com/blog/?p=5994
package main
// Generate RSA signing files via shell (adjust as needed):
//
// $ openssl genrsa -out app.rsa 1024
// $ openssl rsa -in app.rsa -pubout > app.rsa.pub
//
// Code borrowed and modified from the following sources:
// https://www.youtube.com/watch?v=dgJFeqeXVKw
// https://goo.gl/ofVjK4
@chadlung
chadlung / main.go
Last active June 2, 2016 07:21
Fixing a race condition with a mutex (trivial example)
package main
import (
"fmt"
"sync"
)
func main() {
finished := make(chan bool, 1)
@chadlung
chadlung / main.go
Last active May 27, 2016 01:37
Introducing a race condition with Go
package main
import (
"fmt"
)
func main() {
// This code introduces a race condition!!!
finished := make(chan bool, 1)
package main
import (
"fmt"
"os"
)
func main() {
fmt.Println("hello...")
fmt.Println("MYVAR:", os.Getenv("MYVAR"))
@chadlung
chadlung / main.go
Last active September 24, 2015 22:13
package main
import (
"fmt"
"log"
"github.com/spf13/viper"
_ "github.com/spf13/viper/remote"
)
@chadlung
chadlung / step5-main.go
Last active April 3, 2018 04:04
Go: Simple, Easy, Fast - Building a Go (golang) REST Service with Gorilla - Step 5: http://www.giantflyingsaucer.com/blog/?p=5635
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"github.com/gorilla/mux"
)
@chadlung
chadlung / step4-main.go
Created July 6, 2015 23:06
Go: Simple, Easy, Fast - Building a Go (golang) REST Service with Gorilla - Step 4: http://www.giantflyingsaucer.com/blog/?p=5635
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"github.com/gorilla/mux"
)
@chadlung
chadlung / step3-main.go
Created July 6, 2015 22:34
Go: Simple, Easy, Fast - Building a Go (golang) REST Service with Gorilla - Step 3: http://www.giantflyingsaucer.com/blog/?p=5635
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"github.com/gorilla/mux"
)
@chadlung
chadlung / step2-main.go
Created July 6, 2015 21:59
Go: Simple, Easy, Fast - Building a Go (golang) REST Service with Gorilla - Step 2: http://www.giantflyingsaucer.com/blog/?p=5635
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"github.com/gorilla/mux"
)
@chadlung
chadlung / step1-main.go
Created July 6, 2015 16:12
Go: Simple, Easy, Fast - Building a Go (golang) REST Service with Gorilla - Step 1: http://www.giantflyingsaucer.com/blog/?p=5635
package main
import (
"fmt"
"log"
"net/http"
"github.com/gorilla/mux"
)