Initial commit

This commit is contained in:
2024-09-20 17:21:36 -04:00
commit 2c3df630d8
7 changed files with 144 additions and 0 deletions
+59
View File
@@ -0,0 +1,59 @@
// Service hello implements a simple hello world REST API.
package hello
import (
"context"
)
// Welcome to Encore!
// This is a simple "Hello World" project to get you started.
//
// To run it, execute "encore run" in your favorite shell.
// ==================================================================
// This is a public REST API that responds with a personalized greeting.
// Learn more about defining APIs with Encore:
// https://encore.dev/docs/primitives/services-and-apis
//
// To call it, run in your terminal:
//
// curl http://localhost:4000/hello/World
//
//encore:api public path=/hello/:name
func World(ctx context.Context, name string) (*Response, error) {
msg := "Hello, " + name + "!"
return &Response{Message: msg}, nil
}
type Response struct {
Message string
}
// ==================================================================
// Encore comes with a built-in local development dashboard for
// exploring your API, viewing documentation, debugging with
// distributed tracing, and more:
//
// http://localhost:9400
//
// ==================================================================
// Next steps
//
// 1. Deploy your application to the cloud
//
// git add -A .
// git commit -m 'Commit message'
// git push encore
//
// 2. To continue exploring Encore, check out one of these topics:
//
// Defining APIs and Services: https://encore.dev/docs/primitives/services-and-apis
// Using SQL databases: https://encore.dev/docs/develop/databases
// Authenticating users: https://encore.dev/docs/develop/auth
// Building a Slack bot: https://encore.dev/docs/tutorials/slack-bot
// Building a REST API: https://encore.dev/docs/tutorials/rest-api
// Building an Event-Driven app: https://encore.dev/docs/tutorials/uptime
+22
View File
@@ -0,0 +1,22 @@
package hello
import (
"context"
"strings"
"testing"
)
// Run tests using `encore test`, which compiles the Encore app and then runs `go test`.
// It supports all the same flags that the `go test` command does.
// You automatically get tracing for tests in the local dev dash: http://localhost:9400
// Learn more: https://encore.dev/docs/develop/testing
func TestWorld(t *testing.T) {
const in = "Jane Doe"
resp, err := World(context.Background(), in)
if err != nil {
t.Fatal(err)
}
if got := resp.Message; !strings.Contains(got, in) {
t.Errorf("World(%q) = %q, expected to contain %q", in, got, in)
}
}