Skip to content

Commit

Permalink
Go Reportcard fixes and badge
Browse files Browse the repository at this point in the history
  • Loading branch information
renevo committed Aug 27, 2021
1 parent 2c5a916 commit 802177e
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# RPC Package

[![Go Reference](https://pkg.go.dev/badge/github.com/renevo/rpc.svg)](https://pkg.go.dev/github.com/renevo/rpc)
[![Go Report Card](https://goreportcard.com/badge/github.com/renevo/rpc)](https://goreportcard.com/report/github.com/renevo/rpc)

Based off of (*copied from*) the `net/rpc` package with the following changes:

Expand Down
5 changes: 3 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func (e ServerError) Error() string {
return string(e)
}

// ErrShutdown is returned when the client has been closed and a call to Go or Call is executed.
var ErrShutdown = errors.New("connection is shut down")

// Client represents an RPC Client.
Expand Down Expand Up @@ -110,7 +111,7 @@ func (client *Client) Call(ctx context.Context, serviceMethod string, args inter
}
}

// send will execute the call over the wire and input will recieve/complete
// send will execute the call over the wire and input will receive/complete
func (client *Client) send(ctx context.Context, call *Call) {
client.reqMutex.Lock()
defer client.reqMutex.Unlock()
Expand All @@ -124,7 +125,7 @@ func (client *Client) send(ctx context.Context, call *Call) {
return
}

requestID := pseudo_uuid()
requestID := pseudoUUID()
client.pending[requestID] = call
client.mutex.Unlock()

Expand Down
3 changes: 1 addition & 2 deletions doc.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*
Package rpc provides access to the exported methods of an object across a
/* Package rpc provides access to the exported methods of an object across a
network or other I/O connection. A server registers an object, making it visible
as a service with the name of the type of the object. After registration, exported
methods of the object will be accessible remotely. A server may register multiple
Expand Down
4 changes: 4 additions & 0 deletions examples/helloworld/helloworld.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@ import (
"github.com/renevo/rpc"
)

// Client is a sample hellowworld client
type Client struct {
*rpc.Client
}

// Hello to the server!
func (c *Client) Hello(ctx context.Context, name string) (string, error) {
var msg string
err := c.Client.Call(ctx, "Server.Hello", name, &msg)
return msg, err
}

// Server is a sample hellow world server
type Server int

// Hello from the client
func (Server) Hello(ctx context.Context, name string, msg *string) error {
fmt.Fprintf(os.Stdout, "Hello Request ID: %q\n", rpc.ContextID(ctx))

Expand Down
1 change: 1 addition & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
// contains an error when it is used.
var invalidRequest = struct{}{}

// Server represents an RPC Server.
type Server struct {
serviceMap sync.Map
reqLock sync.Mutex // protects freeReq
Expand Down
2 changes: 1 addition & 1 deletion util.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

// Note - NOT RFC4122 compliant
func pseudo_uuid() (uuid string) {
func pseudoUUID() (uuid string) {
b := make([]byte, 16)
_, _ = rand.Read(b)

Expand Down

0 comments on commit 802177e

Please sign in to comment.