templ is a great view framework but there is no clear documentation (as of writing) showing how to use it with the Echo web framework. This short guide should show you how to set it up:
Install templ and echo:
go get github.com/a-h/templ
<script lang="ts"> | |
export let label: string | |
export let type: string = "text" | |
export let value: string = "" | |
export let disabled: boolean = false | |
export let validate: (val: string) => boolean | |
export let valid: boolean = false | |
let id = `field-${Math.floor(Math.random() * 1000)}` |
await run(); | |
async function run() { | |
let loop = 0; | |
while (true) { | |
loop++; | |
console.log("loop:", loop); | |
const items = get_items(); | |
if (!items.length) break; |
On Android devices, if you want to create a file input that prompts the
user to either choose an image from their photo album or take a picture with their
camera, you'll need this basically undocumented capture
attribute added to your input's accept
property:
<input type="file" accept="image/*;capture=camera" />
For a project I'm working on, I need to ship a single server binary with all static files embedded and use that for the frontend of the server. The backend has a variety of routes which the frontend calls.
The frontend is a SvelteKit static app built to ./frontend/build
. Here is the
Echo configuration to get these files serving at the root of the web server:
If you want to run your own app on a Debian system, like a RaspberryPi, you'll need to build the binary for the given device then setup systemd to run the binary.
Given you have an app called myapp
, first create a service file to run your app, say at myapp.service
on your local system:
[Unit]
Description=Some description here...
After=network.target
Want to release a new binary on Github for every new git tag (e.g. v1.2.7
)? Here is a simple Github Actions yaml config file that should get you started.
This script will automatically checkout your code, setup the correct version of go as defined in your go.mod
file
and build your go binary (in this case using a Makefile
default target), then upload it to a new Github Release.
# .github/workflows/release.yml
name: Build and release Go Project
Whew, what a mouthful.
Cloudflare Workers is an excellent platform for deploying a variety of applications but it has some limitations compared to Cloudflare's other product, Pages.
Pages gives you git integration which gives you auto-deploying via git push as well as pull request preview deployment links so you can test out features before pushing to production.
However, it's not super clear how to deploy a bare worker to Cloudflare Pages as Pages is more tailored right now for apps (SvelteKit, Astro, Next, etc), that is why I wrote up this little guide.