Skip to content
Snippets Groups Projects
Commit 75515062 authored by Josh Brooks's avatar Josh Brooks
Browse files

Make endpoint even simpler, fix main.go

parent 5b4fa6b6
No related branches found
No related tags found
1 merge request!2Write restlike server example (single use)
......@@ -5,20 +5,6 @@ import (
"gitlab.com/elixxir/client/restlike"
)
// endpoint implements the restlike.Callback interface.
type endpoint struct {
uri restlike.URI
method restlike.Method
}
// NewEndpoint is a constructor for an endpoint.
func NewEndpoint(uri restlike.URI, method restlike.Method) *endpoint {
return &endpoint{
uri: uri,
method: method,
}
}
// Callback will be called whenever a message is received by the server
// with a matching restlike.Method and restlike.URI.
//
......@@ -26,8 +12,7 @@ func NewEndpoint(uri restlike.URI, method restlike.Method) *endpoint {
// the lower level of the restlike package returns an error
// to the requester.
// User-defined message handling logic goes here.
func (e *endpoint) Callback(
request *restlike.Message) (response *restlike.Message) {
func Callback(request *restlike.Message) (response *restlike.Message) {
jww.INFO.Printf("Request received: %v", request)
return
}
......@@ -37,6 +37,10 @@ func main() {
certificatePath := "../mainnet.crt"
ndfPath := "ndf.json"
// Set the restlike parameters
exampleURI := restlike.URI("handleClient")
exampleMethod := restlike.Get
// Check if state exists
if _, err := os.Stat(statePath); errors.Is(err, fs.ErrNotExist) {
......@@ -124,16 +128,10 @@ func main() {
restlikeServer := single.NewServer(identity.ID, dhKeyPrivateKey,
grp, e2eClient.GetCmix())
// Implement restlike endpoint---------------------------------------------------
// Set parameters to value(s) of your choice
exampleURI := restlike.URI("handleClient")
exampleMethod := restlike.Method(0)
endPoint := NewEndpoint(exampleURI, exampleMethod)
// Implement restlike endpoint---------------------------------------------
// Add endpoint
err = restlikeServer.GetEndpoints().Add(exampleURI, exampleMethod,
endPoint.Callback)
err = restlikeServer.GetEndpoints().Add(exampleURI, exampleMethod, Callback)
if err != nil {
jww.FATAL.Panicf("Failed to add endpoint to server: %v", err)
}
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment