Skip to content

Instantly share code, notes, and snippets.

@hami9x
Created May 30, 2014 11:50
Show Gist options
  • Save hami9x/4c562f7264070bd1dd5c to your computer and use it in GitHub Desktop.
Save hami9x/4c562f7264070bd1dd5c to your computer and use it in GitHub Desktop.
gocode log
2014/05/30 18:48:55 -------------------------------------------------------
2014/05/30 18:48:55 Import path "fmt" was not resolved
2014/05/30 18:48:55 Gocode's build context is:
2014/05/30 18:48:55 GOROOT: /usr/local/go
2014/05/30 18:48:55 GOPATH: /home/phaikawl/Dev/go
2014/05/30 18:48:55 GOOS: linux
2014/05/30 18:48:55 GOARCH: 386
2014/05/30 18:48:55 lib-path: ""
2014/05/30 18:48:55 Import path "reflect" was not resolved
2014/05/30 18:48:55 Gocode's build context is:
2014/05/30 18:48:55 GOROOT: /usr/local/go
2014/05/30 18:48:55 GOPATH: /home/phaikawl/Dev/go
2014/05/30 18:48:55 GOOS: linux
2014/05/30 18:48:55 GOARCH: 386
2014/05/30 18:48:55 lib-path: ""
2014/05/30 18:48:55 Import path "github.com/phaikawl/wade/services/http" was not resolved
2014/05/30 18:48:55 Gocode's build context is:
2014/05/30 18:48:55 GOROOT: /usr/local/go
2014/05/30 18:48:55 GOPATH: /home/phaikawl/Dev/go
2014/05/30 18:48:55 GOOS: linux
2014/05/30 18:48:55 GOARCH: 386
2014/05/30 18:48:55 lib-path: ""
2014/05/30 18:48:55 extracted expression tokens: []main.token_item{main.token_item{off:217, tok:4, lit:"http"}}
2014/05/30 18:48:55 Offset: 0
2014/05/30 18:48:55 Number of candidates found: 0
2014/05/30 18:48:55 Candidates are:
2014/05/30 18:48:55 =======================================================
2014/05/30 18:48:56 Got autocompletion request for '/home/phaikawl/Dev/go/src/github.com/phaikawl/wade/promise.go'
2014/05/30 18:48:56 Cursor at: 218
2014/05/30 18:48:56 -------------------------------------------------------
package wade
import (
"fmt"
"reflect"
"github.com/phaikawl/wade/services/http"
)
type Promise struct {
model interface{}
d http.Deferred
}
func NewPromise(model interface{}, op http.Deferred) *Promise {
h#
return &Promise{model, op}
}
func (p *Promise) Model() interface{} {
return p.model
}
//Model updater type assertion
func (p *Promise) muTypeAssert(fn ModelUpdater) {
tpFn := reflect.TypeOf(fn)
if tpFn.Kind() != reflect.Func {
panic("The return of promise handler must be a function.")
}
paramType := tpFn.In(0).Name()
if paramType == "" {
paramType = tpFn.In(0).Elem().Name()
}
modelType := reflect.TypeOf(p.model).Name()
if modelType == "" {
modelType = reflect.TypeOf(p.model).Elem().Name()
}
if paramType != modelType {
panic(fmt.Sprintf(`The parameter of the promise modelUpdater function (now has type %v) must be of the same type as
the promise's model (of type %v).`, paramType, modelType))
}
}
type ModelUpdater interface{}
type PromiseHandlerFunc func(data *http.Response) ModelUpdater
func (p *Promise) handle(fn PromiseHandlerFunc) http.HttpDoneHandler {
return func(r *http.Response) {
mu := fn(r)
p.muTypeAssert(mu)
reflect.ValueOf(mu).Call([]reflect.Value{reflect.ValueOf(p.model)})
}
}
func (p *Promise) OnSuccess(fn PromiseHandlerFunc) {
p.d.Done(p.handle(fn))
}
func (p *Promise) OnFail(fn PromiseHandlerFunc) {
p.d.Fail(p.handle(fn))
}
func (p *Promise) OnComplete(fn PromiseHandlerFunc) {
p.d.Then(p.handle(fn))
}
//Manually resolve the promise
func (p *Promise) Resolve() {
p.d.Resolve()
}
func (p *Promise) fakeResolve(fn PromiseHandlerFunc) {
(p.handle(fn))(http.NewResponse("", ""))
}
2014/05/30 18:48:56 -------------------------------------------------------
2014/05/30 18:48:56 Import path "fmt" was not resolved
2014/05/30 18:48:56 Gocode's build context is:
2014/05/30 18:48:56 GOROOT: /usr/local/go
2014/05/30 18:48:56 GOPATH: /home/phaikawl/Dev/go
2014/05/30 18:48:56 GOOS: linux
2014/05/30 18:48:56 GOARCH: 386
2014/05/30 18:48:56 lib-path: ""
2014/05/30 18:48:56 Import path "reflect" was not resolved
2014/05/30 18:48:56 Gocode's build context is:
2014/05/30 18:48:56 GOROOT: /usr/local/go
2014/05/30 18:48:56 GOPATH: /home/phaikawl/Dev/go
2014/05/30 18:48:56 GOOS: linux
2014/05/30 18:48:56 GOARCH: 386
2014/05/30 18:48:56 lib-path: ""
2014/05/30 18:48:56 Import path "github.com/phaikawl/wade/services/http" was not resolved
2014/05/30 18:48:56 Gocode's build context is:
2014/05/30 18:48:56 GOROOT: /usr/local/go
2014/05/30 18:48:56 GOPATH: /home/phaikawl/Dev/go
2014/05/30 18:48:56 GOOS: linux
2014/05/30 18:48:56 GOARCH: 386
2014/05/30 18:48:56 lib-path: ""
2014/05/30 18:48:56 Offset: 0
2014/05/30 18:48:56 Number of candidates found: 0
2014/05/30 18:48:56 Candidates are:
2014/05/30 18:48:56 =======================================================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment