Skip to content

Instantly share code, notes, and snippets.

@alexedwards
alexedwards / Makefile
Created May 2, 2023 16:04
Makefile targets for working with sqlite
View Makefile
## db/connect: create to the local database
.PHONY: db/connect
db/connect:
sqlite3 db.sqlite
## db/migrations/new name=$1: create a new migration
.PHONY: db/migrations/new
db/migrations/new:
go run -tags 'sqlite3' github.com/golang-migrate/migrate/v4/cmd/migrate@latest create -seq -ext=.sql -dir=./resources/migrations ${name}
@alexedwards
alexedwards / Makefile
Last active May 26, 2023 07:48
Boilerplate Makefile for Go projects
View Makefile
# Change these variables as necessary.
MAIN_PACKAGE_PATH := ./cmd/example
BINARY_NAME := example
# ==================================================================================== #
# HELPERS
# ==================================================================================== #
## help: print this help message
.PHONY: help
View main.go
package main
import (
"encoding/json"
"errors"
"fmt"
"io"
"log"
"net/http"
"strings"
View workflow.yml
name: Audit and deploy
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
View workflow.yml
name: Audit
on:
push:
branches:
- main
pull_request:
branches:
- main
@alexedwards
alexedwards / index.html
Last active September 17, 2021 09:56
HTML skeleton
View index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Your Page Title</title>
<meta name="description" content="Brief description">
<meta name="author" content="Your name">
View gist:fa02ec95402f687e5f08f54a575a55c7
func (app *application) showMovieHandler(w http.ResponseWriter, r *http.Request) {
id, err := app.readIDParam(r)
if err != nil {
// IT'S THIS LINE HERE THAT YOU NEED TO CHANGE to use the new notFoundResponse() helper.
app.notFoundResponse(w, r)
return
}
movie := data.Movie{
ID: id,
CreatedAt: time.Now(),
View gist:41f7e747ee10287bb881fab9e36ed07c
package main
import (
"net/http"
"github.com/bmizerany/pat"
"github.com/justinas/alice"
)
func (app *application) routes() http.Handler {
View gist:3e158aba800a3044f31bda3d32c72c56
package jsonlog
import (
"encoding/json"
"io"
"os"
"runtime/debug"
"sync"
"time"
)
View gist:a175f4da955cbf57cf2c10f6798a8a6f
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<h1>Simple CORS</h1>
<output></output>
<script>
document.addEventListener('DOMContentLoaded', function() {