Skip to content

Instantly share code, notes, and snippets.

@captncraig
Last active August 29, 2015 14:13
Show Gist options
  • Save captncraig/e2bc7e7d1a0cb2c8127b to your computer and use it in GitHub Desktop.
Save captncraig/e2bc7e7d1a0cb2c8127b to your computer and use it in GitHub Desktop.

Revisions

  1. Craig Peterson revised this gist Jan 12, 2015. 2 changed files with 17 additions and 22 deletions.
    22 changes: 8 additions & 14 deletions BarService.after.go
    Original file line number Diff line number Diff line change
    @@ -3,12 +3,13 @@ type BarServiceProcessor struct {
    handler BarService
    }

    func (p *BarServiceProcessor) GetProcessorFunction(key string) (processor func(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException), ok bool) {
    func (p *BarServiceProcessor) runProcessorFunction(key string, seqId int32, iprot, oprot thrift.TProtocol) (found, ok bool, err thrift.TException) {
    switch key {
    case "ping":
    return p.Process_Ping, true
    ok, err = p.Process_Ping(seqId, iprot, oprot)
    return true, ok, err
    default:
    return p.FooServiceProcessor.GetProcessorFunction(key)
    return p.FooServiceProcessor.runProcessorFunction(key, seqId, iprot, oprot)
    }
    }

    @@ -21,19 +22,12 @@ func (p *BarServiceProcessor) Process(iprot, oprot thrift.TProtocol) (success bo
    if err != nil {
    return false, err
    }
    if processor, ok := p.GetProcessorFunction(name); ok {
    return processor(seqId, iprot, oprot)
    if found, ok, err := p.runProcessorFunction(name, seqId, iprot, oprot); found {
    return ok, err
    }
    iprot.Skip(thrift.STRUCT)
    iprot.ReadMessageEnd()
    x8 := thrift.NewTApplicationException(thrift.UNKNOWN_METHOD, "Unknown function "+name)
    oprot.WriteMessageBegin(name, thrift.EXCEPTION, seqId)
    x8.Write(oprot)
    oprot.WriteMessageEnd()
    oprot.Flush()
    return false, x8
    //same not found stuff
    }

    func (p *BarServiceProcessor) Process_Ping(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
    //...
    //...
    }
    17 changes: 9 additions & 8 deletions FooService.after.go
    Original file line number Diff line number Diff line change
    @@ -2,12 +2,13 @@ type FooServiceProcessor struct {
    handler FooService
    }

    func (p *FooServiceProcessor) GetProcessorFunction(key string) (processor func(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException), ok bool) {
    func (p *FooServiceProcessor) runProcessorFunction(key string, seqId int32, iprot, oprot thrift.TProtocol) (found, ok bool, err thrift.TException) {
    switch key {
    case "add1":
    return p.Process_Add1, true
    ok, err = p.Process_Add1(seqId, iprot, oprot)
    return true, ok, err
    default:
    return nil, false
    return false, false, nil
    }
    }

    @@ -20,12 +21,12 @@ func (p *FooServiceProcessor) Process(iprot, oprot thrift.TProtocol) (success bo
    if err != nil {
    return false, err
    }
    if processor, ok := p.GetProcessorFunction(name); ok {
    return processor(seqId, iprot, oprot)
    if found, ok, err := p.runProcessorFunction(name, seqId, iprot, oprot); found {
    return ok, err
    }
    //unchanged...
    //same not found stuff
    }

    func (p *FooServiceProcessor) Process_Add1(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
    //Body Unaffected
    }
    //same body...
    }
  2. Craig Peterson created this gist Jan 12, 2015.
    39 changes: 39 additions & 0 deletions BarService.after.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    type BarServiceProcessor struct {
    *FooServiceProcessor
    handler BarService
    }

    func (p *BarServiceProcessor) GetProcessorFunction(key string) (processor func(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException), ok bool) {
    switch key {
    case "ping":
    return p.Process_Ping, true
    default:
    return p.FooServiceProcessor.GetProcessorFunction(key)
    }
    }

    func NewBarServiceProcessor(handler BarService) *BarServiceProcessor {
    return &BarServiceProcessor{NewFooServiceProcessor(handler), handler}
    }

    func (p *BarServiceProcessor) Process(iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
    name, _, seqId, err := iprot.ReadMessageBegin()
    if err != nil {
    return false, err
    }
    if processor, ok := p.GetProcessorFunction(name); ok {
    return processor(seqId, iprot, oprot)
    }
    iprot.Skip(thrift.STRUCT)
    iprot.ReadMessageEnd()
    x8 := thrift.NewTApplicationException(thrift.UNKNOWN_METHOD, "Unknown function "+name)
    oprot.WriteMessageBegin(name, thrift.EXCEPTION, seqId)
    x8.Write(oprot)
    oprot.WriteMessageEnd()
    oprot.Flush()
    return false, x8
    }

    func (p *BarServiceProcessor) Process_Ping(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
    //...
    }
    17 changes: 17 additions & 0 deletions BarService.before.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    type BarServiceProcessor struct {
    *FooServiceProcessor
    }

    func NewBarServiceProcessor(handler BarService) *BarServiceProcessor {
    self7 := &BarServiceProcessor{NewFooServiceProcessor(handler)}
    self7.AddToProcessorMap("ping", &barServiceProcessorPing{handler: handler})
    return self7
    }

    type barServiceProcessorPing struct {
    handler BarService
    }

    func (p *barServiceProcessorPing) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
    //Body Unaffected
    }
    31 changes: 31 additions & 0 deletions FooService.after.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    type FooServiceProcessor struct {
    handler FooService
    }

    func (p *FooServiceProcessor) GetProcessorFunction(key string) (processor func(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException), ok bool) {
    switch key {
    case "add1":
    return p.Process_Add1, true
    default:
    return nil, false
    }
    }

    func NewFooServiceProcessor(handler FooService) *FooServiceProcessor {
    return &FooServiceProcessor{handler: handler}
    }

    func (p *FooServiceProcessor) Process(iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
    name, _, seqId, err := iprot.ReadMessageBegin()
    if err != nil {
    return false, err
    }
    if processor, ok := p.GetProcessorFunction(name); ok {
    return processor(seqId, iprot, oprot)
    }
    //unchanged...
    }

    func (p *FooServiceProcessor) Process_Add1(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
    //Body Unaffected
    }
    43 changes: 43 additions & 0 deletions FooService.before.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    type FooServiceProcessor struct {
    processorMap map[string]thrift.TProcessorFunction
    handler FooService
    }

    func (p *FooServiceProcessor) AddToProcessorMap(key string, processor thrift.TProcessorFunction) {
    p.processorMap[key] = processor
    }

    func (p *FooServiceProcessor) GetProcessorFunction(key string) (processor thrift.TProcessorFunction, ok bool) {
    processor, ok = p.processorMap[key]
    return processor, ok
    }

    func (p *FooServiceProcessor) ProcessorMap() map[string]thrift.TProcessorFunction {
    return p.processorMap
    }

    func NewFooServiceProcessor(handler FooService) *FooServiceProcessor {

    self2 := &FooServiceProcessor{handler: handler, processorMap: make(map[string]thrift.TProcessorFunction)}
    self2.processorMap["add1"] = &fooServiceProcessorAdd1{handler: handler}
    return self2
    }

    func (p *FooServiceProcessor) Process(iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
    name, _, seqId, err := iprot.ReadMessageBegin()
    if err != nil {
    return false, err
    }
    if processor, ok := p.GetProcessorFunction(name); ok {
    return processor.Process(seqId, iprot, oprot)
    }
    //unchanged...
    }

    type fooServiceProcessorAdd1 struct {
    handler FooService
    }

    func (p *fooServiceProcessorAdd1) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
    //Body Unaffected
    }
    9 changes: 9 additions & 0 deletions foo.thrift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    namespace * foo

    service FooService{
    i32 add1(1: i32 x)
    }

    service BarService extends FooService{
    void ping()
    }