Skip to content

Instantly share code, notes, and snippets.

View abserari's full-sized avatar
🐱
Let's build a better world

DingRui Yang abserari

🐱
Let's build a better world
View GitHub Profile
@abserari
abserari / grpc.go
Created August 17, 2019 15:11
reflect call method grpc method
// CallUnary
// [3]reflect.Value in[0] is context.Context, in[1] is your message type which generated by pb file.
// in[2] is grpc.CallOption
func (c *Client) CallUnary(methodName string,in []reflect.Value)(interface{},error) {
m, ok := reflect.TypeOf(c.c).MethodByName(methodName)
if !ok{
log.Fatal("method not found")
return nil,errors.New("method not found")
}
@abserari
abserari / BitSwap.md
Last active June 17, 2019 13:58
design for IPFS and go code

This allows nodes to keep track of history and avoid tampering.

type Ledger struct {
owner NodeId
partner NodeId
bytes_sent int
bytes_recv int
timestamp Timestamp
}
@abserari
abserari / closure.md
Created June 12, 2019 19:30
Good for Code
func (s SqlTokenStore) Save(token *model.Token) store.StoreChannel {
  return store.Do(func(result *store.StoreResult) {
    if result.Err = token.IsValid(); result.Err != nil {
      return
    }
    
    if err := s.GetMaster().Insert(token); err != nil {
      result.Err = model.NewAppError("SqlTokenStore.Save", "store.sql_recover.save.app_error", nil, "", http.StatusInternalServerError)
    }
@abserari
abserari / Hi Friends.md
Last active August 28, 2020 14:57
Welcome to be my Company