Created
February 19, 2017 14:07
-
-
Save maniankara/b8ddb81ea2a643e67c9c48c9f1eaca8f to your computer and use it in GitHub Desktop.
first class function: passing function to another
This file contains hidden or 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
package fragments | |
import ( | |
"net/http" | |
"bytes" | |
) | |
// define a type function | |
type httpReqFunc func () (resp *http.Response, err error) | |
func example(fn httpReqFunc, ret int) { | |
resp, err := fn() | |
// perform some actions/handling here | |
return resp, err | |
} | |
func caller() { | |
example(func() (resp *http.Response, err error) { | |
return http.Post("http://google.com", "application/json", bytes.NewReader("")) | |
}, 10) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment