Skip to content

Commit

Permalink
Add gRPC setup, server logic and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hindenbug committed Aug 24, 2021
1 parent cc0b790 commit 1ddc2f8
Show file tree
Hide file tree
Showing 11 changed files with 1,192 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
.vscode
7 changes: 7 additions & 0 deletions Makefile
@@ -0,0 +1,7 @@
compile:
protoc api/log/**/*.proto \
--go_out=. \
--go-grpc_out=. \
--go_opt=paths=source_relative \
--go-grpc_opt=paths=source_relative \
--proto_path=.
38 changes: 38 additions & 0 deletions api/log/v1/error.go
@@ -0,0 +1,38 @@
package log_v1

import (
"fmt"

"google.golang.org/genproto/googleapis/rpc/errdetails"
status "google.golang.org/grpc/status"
)

type ErrOffsetOutOfRange struct {
Offset uint64
}

func (e ErrOffsetOutOfRange) GRPCStatus() *status.Status {
st := status.New(
404,
fmt.Sprintf("offset out of range: %d", e.Offset),
)

msg := fmt.Sprintf(
"The requested offset is outside the log's range: %d",
e.Offset)

d := &errdetails.LocalizedMessage{Locale: "en-US",
Message: msg,
}
std, err := st.WithDetails(d)

if err != nil {
return st
}

return std
}

func (e ErrOffsetOutOfRange) Error() string {
return e.GRPCStatus().Err().Error()
}

0 comments on commit 1ddc2f8

Please sign in to comment.