Skip to content

Instantly share code, notes, and snippets.

@lusis
Created May 7, 2021 14:59
Show Gist options
  • Select an option

  • Save lusis/181a80b975e9a7551e66187cfc36db3a to your computer and use it in GitHub Desktop.

Select an option

Save lusis/181a80b975e9a7551e66187cfc36db3a to your computer and use it in GitHub Desktop.

Revisions

  1. lusis created this gist May 7, 2021.
    25 changes: 25 additions & 0 deletions alternate-foo.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    package fooservice

    import (
    "github.com/segmentio/ksuid"

    idgen "github.com/lusis/foobar/idgen"
    pb "github.com/lusis/foobar/pb"
    storer "github.com/lusis/foobar/storer"
    )

    // FooService implements the pb.FooService
    type FooService struct {
    pb.UnimplementedFooServiceServer
    store storer.FooEntriesStorer
    idFunc idgen.IDFunc
    }


    // New ...
    func New(store storer.FooEntriesStorer) (*FooService, error) {
    return &FooService{
    store: store,
    idFunc: idgen.DefaultIDFunc,
    }, nil
    }
    7 changes: 7 additions & 0 deletions alternate-idgen.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    package idgen

    type IDFunc func() string

    func DefaultIDFunc() string {
    return ksuid.New().String()
    }
    27 changes: 27 additions & 0 deletions foo.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    package fooservice

    import (
    "github.com/segmentio/ksuid"

    pb "github.com/lusis/foobar/pb"
    storer "github.com/lusis/foobar/storer"
    )

    // FooService implements the pb.FooService
    type FooService struct {
    pb.UnimplementedFooServiceServer
    store storer.FooEntriesStorer
    idFunc func() string
    }

    func defaultIDFunc() string {
    return ksuid.New().String()
    }

    // New ...
    func New(store storer.FooEntriesStorer) (*FooService, error) {
    return &FooService{
    store: store,
    idFunc: defaultIDFunc,
    }, nil
    }