Skip to content

Commit

Permalink
Go components no longer need main
Browse files Browse the repository at this point in the history
Signed-off-by: itowlson <[email protected]>
  • Loading branch information
itowlson committed Jan 13, 2025
1 parent d868b37 commit 68a344f
Show file tree
Hide file tree
Showing 9 changed files with 2 additions and 31 deletions.
3 changes: 0 additions & 3 deletions content/spin/v3/ai-sentiment-analysis-api-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -757,9 +757,6 @@ func performSentimentAnalysis(w http.ResponseWriter, r *http.Request, ps spinhtt
return
}
}

func main() {}

```

{{ blockEnd }}
Expand Down
9 changes: 0 additions & 9 deletions content/spin/v3/go-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -141,8 +139,6 @@ func init() {
}
})
}

func main() {}
```

The Outbound HTTP Request example above can be built using the `tingygo` toolchain:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 0 additions & 4 deletions content/spin/v3/http-trigger.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Expand Down
3 changes: 0 additions & 3 deletions content/spin/v3/key-value-store-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,6 @@ func init() {
}
})
}

func main() {}

```

{{ blockEnd }}
Expand Down
6 changes: 2 additions & 4 deletions content/spin/v3/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -657,8 +657,6 @@ func init() {
fmt.Fprintln(w, "Hello Fermyon!")
})
}

func main() {}
```

{{ blockEnd }}
Expand Down
2 changes: 0 additions & 2 deletions content/spin/v3/rdbms-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,6 @@ func init() {
json.NewEncoder(w).Encode(pets)
})
}

func main() {}
```

{{ blockEnd }}
Expand Down
2 changes: 0 additions & 2 deletions content/spin/v3/redis-trigger.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ func init() {
return nil
})
}

func main() {}
```

{{ blockEnd }}
Expand Down
2 changes: 0 additions & 2 deletions content/spin/v3/sqlite-api-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,6 @@ func init() {
json.NewEncoder(w).Encode(todos)
})
}

func main() {}
```

**General Notes**
Expand Down
2 changes: 0 additions & 2 deletions content/spin/v3/variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,6 @@ func init() {
fmt.Fprintln(w, "Used an API")
})
}

func main() {}
```

{{ blockEnd }}
Expand Down

0 comments on commit 68a344f

Please sign in to comment.