Skip to content

Instantly share code, notes, and snippets.

@cemeng
Created February 20, 2018 22:39
Show Gist options
  • Save cemeng/4b9141d14b9209c2cbddb24126633783 to your computer and use it in GitHub Desktop.
Save cemeng/4b9141d14b9209c2cbddb24126633783 to your computer and use it in GitHub Desktop.
Golang Study Notes
My Golang study note
@cemeng
Copy link
Author

cemeng commented Feb 22, 2018

22/2

dep -> dependency management in go https://github.com/golang/dep - does blue team use this?

started following gowebexamples.com
unable to start web server on port 80 - wondering why, using log.Fatal helps
log.Fatal(http.ListenAndServe(":80", nil))

Middleware

TIL: you can pass in a function as a param to a function.
A function has a type - the type is determined by the function signature.

func logging(f http.HandlerFunc) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		log.Println(r.URL.Path)
		f(w, r)
	}
}

https://gowebexamples.com/basic-middleware/

Basically middleware is just a function that takes http.HandlerFunc and return http.HandlerFunc

Advanced Middleware

create a middleware type
type Middleware func(http.HandlerFunc) http.HandlerFunc
and you can chain em - you need to create your own Chain method urgh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment