Skip to content

Instantly share code, notes, and snippets.

@lysu
Created March 7, 2016 16:42
Show Gist options
  • Save lysu/d3dff79a6c8bc4f74f20 to your computer and use it in GitHub Desktop.
Save lysu/d3dff79a6c8bc4f74f20 to your computer and use it in GitHub Desktop.
/* 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