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
# Change these variables as necessary. | |
MAIN_PACKAGE_PATH := ./cmd/example | |
BINARY_NAME := example | |
# ==================================================================================== # | |
# HELPERS | |
# ==================================================================================== # | |
## help: print this help message | |
.PHONY: help |
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
. | |
├── books | |
│ ├── handlers.go | |
│ └── models.go | |
├── config | |
│ └── db.go | |
└── main.go |
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
package main | |
import ( | |
"database/sql" | |
"testing" | |
"time" | |
_ "github.com/lib/pq" | |
) |
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
. | |
├── config | |
│ └── config.go | |
├── go.mod | |
├── go.sum | |
├── main.go | |
└── models | |
└── books | |
└── books.go |
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
package cache | |
import ( | |
"sync" | |
"time" | |
) | |
// Cache is a basic in-memory key-value cache implementation. | |
type Cache[K comparable, V any] struct { | |
items map[K]V // The map storing key-value pairs. |
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
CREATE TABLE books ( | |
isbn char(14) NOT NULL, | |
title varchar(255), | |
author varchar(255), | |
price decimal(5,2) | |
); | |
INSERT INTO books (isbn, title, author, price) VALUES | |
('978-1503261969', 'Emma', 'Jayne Austen', 9.44), | |
('978-1514274873', 'Journal of a Soldier', NULL, 5.49), |
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
. | |
├── go.mod | |
├── handlers | |
│ ├── books | |
│ │ └── books.go | |
│ └── env.go | |
├── main.go | |
└── models | |
└── models.go |
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
## 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} |
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
package main | |
import ( | |
"crypto/rand" | |
"crypto/subtle" | |
"encoding/base64" | |
"errors" | |
"fmt" | |
"log" | |
"strings" |
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
package main | |
import ( | |
"encoding/json" | |
"net/http" | |
) | |
func main() {} | |
func healthcheckHandlerEncoder(w http.ResponseWriter, r *http.Request) { |
NewerOlder