Created
March 7, 2016 16:42
-
-
Save lysu/d3dff79a6c8bc4f74f20 to your computer and use it in GitHub Desktop.
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
/* start prcess/process.go */ | |
package process | |
var Fetch Fetch // Gobal variable, but no initilize, and For Extension!!! | |
func Process(x string) { | |
fetch.Fetch(x) | |
} | |
/* end prcess/process.go */ | |
/* start fetch/fetch.go */ | |
package fetch | |
type Fetch interface { | |
Fetch(x string) | |
} | |
/* end fetch/fetch.go */ | |
/* start fetch/http/http.go */ | |
// extract http sub-package | |
package http | |
type httpFetch struct { | |
} | |
// ............ | |
func NewHttpFetch() Fetch { | |
return &httpFetch | |
} | |
/* end fetch/http/http.go */ | |
func init() { | |
// use `http.init` to inject http itself into `proces.fetch` field. | |
process.Fetch = &httpFetch{} | |
} | |
/* start main.go */ | |
package main | |
// just wire http up us import statement. | |
import _ "fetch/http" | |
func main() { | |
process.Process("11211") | |
} | |
/* end main.go */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment