Skip to content

Instantly share code, notes, and snippets.

@rming
Last active February 21, 2019 03:55
Show Gist options
  • Save rming/87e7a4c47a2231142b25d3de4ca3d2f3 to your computer and use it in GitHub Desktop.
Save rming/87e7a4c47a2231142b25d3de4ca3d2f3 to your computer and use it in GitHub Desktop.
go test
package main
import (
"fmt"
"reflect"
)
type AppInterface interface {
run() *App
}
type App struct {
attr string
}
func (self *App) run() *App {
self.attr = "abc"
return self
}
func f(app AppInterface) {
fmt.Println(app)
}
func main() {
var app AppInterface = new(App)
var app1 *App = new(App)
var app2 App
fmt.Println(reflect.TypeOf(app), app)
fmt.Println(reflect.TypeOf(app1), app1)
fmt.Println(reflect.TypeOf(app2), app2)
app.run()
app1.run()
app2.run()
f(app)
f(app1)
f(&app2)
fmt.Println(app.(*App).attr)
fmt.Println(app1.attr)
fmt.Println(app2.attr)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment