Created
February 20, 2018 22:39
-
-
Save cemeng/4b9141d14b9209c2cbddb24126633783 to your computer and use it in GitHub Desktop.
Golang Study Notes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
My Golang study note |
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
21/2 - Focus on today is error handling in Go
Back to Golang learning - learning about error handling in Go:
https://blog.golang.org/error-handling-and-go
Sharing with the group:
https://play.golang.org/p/Mv7FADkEz9V
https://blog.golang.org/error-handling-and-go
My takeaway:
return 0, fmt.Errorf("math: %g", f)
Here is an example:
Further questions: