From 68a344f80caf8c24e5f86058bfa0a89115fdca71 Mon Sep 17 00:00:00 2001 From: itowlson Date: Mon, 13 Jan 2025 14:28:13 +1300 Subject: [PATCH] Go components no longer need `main` Signed-off-by: itowlson --- content/spin/v3/ai-sentiment-analysis-api-tutorial.md | 3 --- content/spin/v3/go-components.md | 9 --------- content/spin/v3/http-trigger.md | 4 ---- content/spin/v3/key-value-store-tutorial.md | 3 --- content/spin/v3/quickstart.md | 6 ++---- content/spin/v3/rdbms-storage.md | 2 -- content/spin/v3/redis-trigger.md | 2 -- content/spin/v3/sqlite-api-guide.md | 2 -- content/spin/v3/variables.md | 2 -- 9 files changed, 2 insertions(+), 31 deletions(-) diff --git a/content/spin/v3/ai-sentiment-analysis-api-tutorial.md b/content/spin/v3/ai-sentiment-analysis-api-tutorial.md index 94d56d37a..2f082d367 100644 --- a/content/spin/v3/ai-sentiment-analysis-api-tutorial.md +++ b/content/spin/v3/ai-sentiment-analysis-api-tutorial.md @@ -757,9 +757,6 @@ func performSentimentAnalysis(w http.ResponseWriter, r *http.Request, ps spinhtt return } } - -func main() {} - ``` {{ blockEnd }} diff --git a/content/spin/v3/go-components.md b/content/spin/v3/go-components.md index 6400b3298..7f059e727 100644 --- a/content/spin/v3/go-components.md +++ b/content/spin/v3/go-components.md @@ -61,8 +61,6 @@ func init() { fmt.Fprintln(w, "Hello Fermyon!") }) } - -func main() {} ``` The Spin HTTP component (written in Go) can be built using the `tingygo` toolchain: @@ -141,8 +139,6 @@ func init() { } }) } - -func main() {} ``` The Outbound HTTP Request example above can be built using the `tingygo` toolchain: @@ -228,9 +224,6 @@ func init() { return nil }) } - -// main function must be included for the compiler but is not executed. -func main() {} ``` The manifest for a Redis application must contain the address of the Redis instance. This is set at the application level: @@ -351,8 +344,6 @@ func init() { } }) } - -func main() {} ``` As with all networking APIs, you must grant access to Redis hosts via the `allowed_outbound_hosts` field in the application manifest: diff --git a/content/spin/v3/http-trigger.md b/content/spin/v3/http-trigger.md index 0afc9cb3d..1debb3edd 100644 --- a/content/spin/v3/http-trigger.md +++ b/content/spin/v3/http-trigger.md @@ -294,8 +294,6 @@ class IncomingHandler(http.IncomingHandler): In Go, you register the handler as a callback in your program's `init` function. Call `spinhttp.Handle`, passing your handler as the sole argument. Your handler takes a `http.Request` record, from the standard `net/http` package, and a `ResponseWriter` to construct the response. -> The do-nothing `main` function is required by TinyGo but is not used; the action happens in the `init` function and handler callback. - ```go package main @@ -312,8 +310,6 @@ func init() { fmt.Fprintln(w, "Hello Fermyon!") }) } - -func main() {} ``` > If you are moving between languages, note that in most other Spin SDKs, your handler _constructs and returns_ a response, but in Go, _Spin_ constructs a `ResponseWriter`, and you write to it; your handler does not return a value. diff --git a/content/spin/v3/key-value-store-tutorial.md b/content/spin/v3/key-value-store-tutorial.md index 0c8fa9be4..19d42438b 100644 --- a/content/spin/v3/key-value-store-tutorial.md +++ b/content/spin/v3/key-value-store-tutorial.md @@ -398,9 +398,6 @@ func init() { } }) } - -func main() {} - ``` {{ blockEnd }} diff --git a/content/spin/v3/quickstart.md b/content/spin/v3/quickstart.md index 3cb83e970..35ed987cf 100644 --- a/content/spin/v3/quickstart.md +++ b/content/spin/v3/quickstart.md @@ -635,8 +635,8 @@ This represents a simple Spin HTTP application (triggered by an HTTP request). [Learn more about the manifest here.](./writing-apps) Now let's have a look at the code. Below is the complete source -code for a Spin HTTP component written in Go. Notice where the work is done. The -`main` function is empty (and Spin never calls it). Instead, the `init` function +code for a Spin HTTP component written in Go. Notice where the work is done. Because this is a component +rather than an application, there is no `main` function. Instead, the `init` function sets up a callback, and passes that callback to `spinhttp.Handle` to register it as the handler for HTTP requests. You can learn more about this structure in the [Go language guide](go-components). @@ -657,8 +657,6 @@ func init() { fmt.Fprintln(w, "Hello Fermyon!") }) } - -func main() {} ``` {{ blockEnd }} diff --git a/content/spin/v3/rdbms-storage.md b/content/spin/v3/rdbms-storage.md index 6bb8ef5bd..d0aa5bc96 100644 --- a/content/spin/v3/rdbms-storage.md +++ b/content/spin/v3/rdbms-storage.md @@ -194,8 +194,6 @@ func init() { json.NewEncoder(w).Encode(pets) }) } - -func main() {} ``` {{ blockEnd }} diff --git a/content/spin/v3/redis-trigger.md b/content/spin/v3/redis-trigger.md index c00ed0b2b..25b43adfb 100644 --- a/content/spin/v3/redis-trigger.md +++ b/content/spin/v3/redis-trigger.md @@ -137,8 +137,6 @@ func init() { return nil }) } - -func main() {} ``` {{ blockEnd }} diff --git a/content/spin/v3/sqlite-api-guide.md b/content/spin/v3/sqlite-api-guide.md index 3641edee4..2ae0d8e6b 100644 --- a/content/spin/v3/sqlite-api-guide.md +++ b/content/spin/v3/sqlite-api-guide.md @@ -224,8 +224,6 @@ func init() { json.NewEncoder(w).Encode(todos) }) } - -func main() {} ``` **General Notes** diff --git a/content/spin/v3/variables.md b/content/spin/v3/variables.md index 3d64dbd68..39ab4af6f 100644 --- a/content/spin/v3/variables.md +++ b/content/spin/v3/variables.md @@ -232,8 +232,6 @@ func init() { fmt.Fprintln(w, "Used an API") }) } - -func main() {} ``` {{ blockEnd }}