-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
386 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
FROM gitpod/workspace-base:latest | ||
|
||
# ------------------------------------ | ||
# Install Go | ||
# ------------------------------------ | ||
ENV GO_VERSION=1.20 | ||
|
||
ENV GOPATH=$HOME/go-packages | ||
ENV GOROOT=$HOME/go | ||
ENV PATH=$GOROOT/bin:$GOPATH/bin:$PATH | ||
RUN curl -fsSL https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz | tar xzs \ | ||
&& printf '%s\n' 'export GOPATH=/workspace/go' \ | ||
'export PATH=$GOPATH/bin:$PATH' > $HOME/.bashrc.d/300-go | ||
|
||
# ------------------------------------ | ||
# Install TinyGo | ||
# ------------------------------------ | ||
ARG TINYGO_VERSION="0.27.0" | ||
RUN wget https://github.com/tinygo-org/tinygo/releases/download/v${TINYGO_VERSION}/tinygo_${TINYGO_VERSION}_amd64.deb | ||
RUN sudo dpkg -i tinygo_${TINYGO_VERSION}_amd64.deb | ||
RUN rm tinygo_${TINYGO_VERSION}_amd64.deb | ||
|
||
RUN go install github.com/go-task/task/v3/cmd/task@latest | ||
RUN go install -v golang.org/x/tools/gopls@latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
image: | ||
file: .gitpod.Dockerfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Serving HTML with Capsule HTTP server | ||
|
||
```bash | ||
# build and install capsule-http | ||
task install | ||
# build the wasm module | ||
task build | ||
# serve the wasm module | ||
task serve | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
version: '3' | ||
|
||
# capsctl usages | ||
tasks: | ||
|
||
# build capsule-http and deploy on OVH | ||
install: | ||
cmds: | ||
- | | ||
echo "📦 Building capsule-http..." | ||
cd ../.. | ||
pwd | ||
env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o capsule-http | ||
ls -lh capsule-http | ||
sudo cp capsule-http /usr/local/bin/capsule-http | ||
capsule-http --version | ||
build: | ||
cmds: | ||
- | | ||
echo "📦 Building index.wasm module..." | ||
tinygo build -o index.wasm \ | ||
-scheduler=none \ | ||
--no-debug \ | ||
-target wasi ./main.go | ||
ls -lh *.wasm | ||
serve: | ||
env: | ||
HTTP_PORT: '7070' | ||
WASM_FILE: './index.wasm' | ||
cmds: | ||
- | | ||
capsule-http --wasm=${WASM_FILE} --httpPort=${HTTP_PORT} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Capsule 💜 Wasm & Wazero</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<style> | ||
.container { min-height: 100vh; display: flex; justify-content: center; align-items: center; text-align: center; } | ||
.title { font-family: "Source Sans Pro", "Helvetica Neue", Arial, sans-serif; display: block; font-weight: 300; font-size: 80px; color: #35495e; letter-spacing: 1px; } | ||
.subtitle { font-family: "Source Sans Pro", "Helvetica Neue", Arial, sans-serif; font-weight: 300; font-size: 32px; color: #526488; word-spacing: 5px; padding-bottom: 15px; } | ||
.links { padding-top: 15px; } | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<section class="container"> | ||
<div> | ||
<h1 class="title">👋 Hello World 🌍</h1> | ||
<h2 class="subtitle">Served with 💜 by Capsule [HTTP] v0.3.9 🥒 [cucumber] 💊</h2> | ||
<h2 class="subtitle">🎉 Happily built thanks to Wazero</h2> | ||
</div> | ||
</section> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,28 @@ | ||
// Package main | ||
// Package main, this module is serving HTML | ||
package main | ||
|
||
import ( | ||
_ "embed" | ||
capsule "github.com/bots-garden/capsule-module-sdk" | ||
) | ||
|
||
var ( | ||
//go:embed index.html | ||
html []byte | ||
) | ||
|
||
func main() { | ||
capsule.SetHandleHTTP(Handle) | ||
capsule.SetHandleHTTP(func (param capsule.HTTPRequest) (capsule.HTTPResponse, error) { | ||
return capsule.HTTPResponse{ | ||
TextBody: string(html), | ||
Headers: `{ | ||
"Content-Type": "text/html; charset=utf-8", | ||
"Cache-Control": "no-cache", | ||
"X-Powered-By": "capsule-module-sdk" | ||
}`, | ||
StatusCode: 200, | ||
}, nil | ||
}) | ||
} | ||
|
||
// Handle function | ||
func Handle(param capsule.HTTPRequest) (capsule.HTTPResponse, error) { | ||
|
||
return capsule.HTTPResponse{ | ||
TextBody: "<h1>👋 Hello World! 🌍</h1>", | ||
Headers: `{ | ||
"Content-Type": "text/html; charset=utf-8", | ||
"Cache-Control": "no-cache", | ||
"X-Powered-By": "capsule-module-sdk" | ||
}`, | ||
StatusCode: 200, | ||
}, nil | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.