From 7feefda4cece2551c7f3c3df256954ade5052e7b Mon Sep 17 00:00:00 2001 From: Marcus Kohlberg <78424526+marcuskohlberg@users.noreply.github.com> Date: Thu, 12 Sep 2024 10:43:34 +0200 Subject: [PATCH] Add related examples to more docs pages (#1386) --- docs/develop/auth.md | 5 +++++ docs/primitives/api-calls.md | 5 +++++ docs/primitives/apis.md | 5 +++++ docs/primitives/cron-jobs.md | 5 +++++ docs/primitives/databases.md | 5 +++++ docs/primitives/pubsub.md | 5 +++++ docs/primitives/raw-endpoints.md | 5 +++++ docs/primitives/secrets.md | 5 +++++ docs/primitives/service-structs.md | 5 +++++ docs/primitives/services.md | 5 +++++ docs/ts/concepts/hello-world.md | 2 +- docs/ts/develop/auth.md | 6 ++++++ docs/ts/primitives/api-calls.mdx | 5 +++++ docs/ts/primitives/pubsub.md | 2 +- docs/ts/primitives/raw-endpoints.mdx | 2 +- 15 files changed, 64 insertions(+), 3 deletions(-) diff --git a/docs/develop/auth.md b/docs/develop/auth.md index b6ad95176d..023878ce2c 100644 --- a/docs/develop/auth.md +++ b/docs/develop/auth.md @@ -69,6 +69,11 @@ func AuthHandler(ctx context.Context, token string) (auth.UID, *Data, error) { } ``` + + ### Without custom user data When you don't require custom user data and it's sufficient to use `auth.UID`, diff --git a/docs/primitives/api-calls.md b/docs/primitives/api-calls.md index b4ffcb94c0..7d68413b59 100644 --- a/docs/primitives/api-calls.md +++ b/docs/primitives/api-calls.md @@ -23,6 +23,11 @@ func MyOtherAPI(ctx context.Context) error { } ``` + + This means your development workflow is as simple as building a monolith, even if you use multiple services. You also get all the benefits of function calls, like compile-time checking of all the parameters and auto-completion in your editor, while still allowing the division of code into logical components, services, and systems. diff --git a/docs/primitives/apis.md b/docs/primitives/apis.md index adb3cd23c0..3a95ba4e0a 100644 --- a/docs/primitives/apis.md +++ b/docs/primitives/apis.md @@ -23,6 +23,11 @@ func Ping(ctx context.Context, params *PingParams) (*PingResponse, error) { } ``` + + ## Access controls When you define an API, you have three options for how it can be accessed: diff --git a/docs/primitives/cron-jobs.md b/docs/primitives/cron-jobs.md index 8ee5bf25dd..980dfb79da 100644 --- a/docs/primitives/cron-jobs.md +++ b/docs/primitives/cron-jobs.md @@ -16,6 +16,11 @@ When you need to run periodic and recurring tasks, Encore's Backend Framework pr When a Cron Job is defined, Encore will call the API of your choice on the schedule you have defined. This means there is no need to maintain any infrastructure, as Encore handles the scheduling, monitoring and execution of Cron Jobs. + + ## Defining a Cron Job To define a Cron Job, all you need to do is to import the `encore.dev/cron` [package](https://pkg.go.dev/encore.dev/cron), diff --git a/docs/primitives/databases.md b/docs/primitives/databases.md index cd23ad9097..b2a51af4fd 100644 --- a/docs/primitives/databases.md +++ b/docs/primitives/databases.md @@ -46,6 +46,11 @@ With this code in place Encore will automatically create the database using Dock For cloud environments, Encore automatically injects the appropriate configuration to authenticate and connect to the database, so once the application starts up the database is ready to be used. + + ## Defining the database schema Database schemas are defined by creating *migration files* in a directory named `migrations` diff --git a/docs/primitives/pubsub.md b/docs/primitives/pubsub.md index 1e3475e7f5..58942170de 100644 --- a/docs/primitives/pubsub.md +++ b/docs/primitives/pubsub.md @@ -37,6 +37,11 @@ var Signups = pubsub.NewTopic[*SignupEvent]("signups", pubsub.TopicConfig{ }) ``` + + ### At-least-once delivery The above example configures the topic to ensure that, for each subscription, events will be delivered _at least once_. diff --git a/docs/primitives/raw-endpoints.md b/docs/primitives/raw-endpoints.md index 188c952d36..af9072bcfa 100644 --- a/docs/primitives/raw-endpoints.md +++ b/docs/primitives/raw-endpoints.md @@ -32,3 +32,8 @@ Experienced Go developers will have already noted this is just a regular Go HTTP (See the net/http documentation for how Go HTTP handlers work.) Learn more about receiving webhooks and using WebSockets in the [receiving regular HTTP requests guide](/docs/how-to/http-requests). + + diff --git a/docs/primitives/secrets.md b/docs/primitives/secrets.md index 6d0b707eb1..097f81ac60 100644 --- a/docs/primitives/secrets.md +++ b/docs/primitives/secrets.md @@ -12,6 +12,11 @@ Of course, we can’t do that – it's horrifyingly insecure! Encore's built-in secrets manager makes it simple to store secrets in a secure way and lets you use them in your program like regular variables. + + ## Using secrets in your application To use a secret in your application, first define it directly in your code by creating an unexported struct named `secrets`, where all fields are of type `string`. For example: diff --git a/docs/primitives/service-structs.md b/docs/primitives/service-structs.md index 81f81497c7..17484882bb 100644 --- a/docs/primitives/service-structs.md +++ b/docs/primitives/service-structs.md @@ -32,6 +32,11 @@ func (s *Service) MyAPI(ctx context.Context) error { } ``` + + ## Calling APIs defined on service structs When using a service struct like above, Encore will create a file named `encore.gen.go` diff --git a/docs/primitives/services.md b/docs/primitives/services.md index f281617b83..459764d435 100644 --- a/docs/primitives/services.md +++ b/docs/primitives/services.md @@ -30,6 +30,11 @@ On disk it might look like this: This means building a microservices architecture is as simple as creating multiple Go packages within your application. See the [app structure documentation](/docs/develop/app-structure) for more details. + + ## Service Initialization Under the hood Encore automatically generates a `main` function that initializes all your infrastructure resources when the application starts up. This means you don't write a `main` function for your Encore application. diff --git a/docs/ts/concepts/hello-world.md b/docs/ts/concepts/hello-world.md index a338ee7c2e..e69665f127 100644 --- a/docs/ts/concepts/hello-world.md +++ b/docs/ts/concepts/hello-world.md @@ -34,7 +34,7 @@ To run it, you simply use `encore run` and the Open Source CLI will automaticall ## Getting started video diff --git a/docs/ts/develop/auth.md b/docs/ts/develop/auth.md index 2fc6862859..55d994fa96 100644 --- a/docs/ts/develop/auth.md +++ b/docs/ts/develop/auth.md @@ -69,6 +69,12 @@ incoming requests to your application, and whenever a request contains an `Authorization` header it will first call the authentication handler to resolve information about the user. + + + ### Rejecting authentication If the auth handler returns an `AuthData` object, Encore will consider the request diff --git a/docs/ts/primitives/api-calls.mdx b/docs/ts/primitives/api-calls.mdx index 04c512540c..a85a346dd7 100644 --- a/docs/ts/primitives/api-calls.mdx +++ b/docs/ts/primitives/api-calls.mdx @@ -22,3 +22,8 @@ export const myOtherAPI = api({}, async (): Promise => { This means your development workflow is as simple as building a monolith, even if you use multiple services. You get all the benefits of function calls, like compile-time checking of all the parameters and auto-completion in your editor, while still allowing the division of code into logical components, services, and systems. + + diff --git a/docs/ts/primitives/pubsub.md b/docs/ts/primitives/pubsub.md index 4287ecd2f9..1a99392432 100644 --- a/docs/ts/primitives/pubsub.md +++ b/docs/ts/primitives/pubsub.md @@ -17,7 +17,7 @@ Encore's Backend Framework lets you use Pub/Sub in a cloud-agnostic declarative ## Creating a Topic diff --git a/docs/ts/primitives/raw-endpoints.mdx b/docs/ts/primitives/raw-endpoints.mdx index ae00ff837c..1331e68eaa 100644 --- a/docs/ts/primitives/raw-endpoints.mdx +++ b/docs/ts/primitives/raw-endpoints.mdx @@ -39,5 +39,5 @@ Hello, raw world!