no longer pass base64 encoding to handlers

This commit is contained in:
1e99 2024-11-08 16:04:00 +01:00
parent 9f1c4dd9e6
commit 08fbba0e0a
3 changed files with 4 additions and 7 deletions

View file

@ -2,7 +2,6 @@ package main
import (
"embed"
"encoding/base64"
"errors"
"log"
"net/http"
@ -37,12 +36,12 @@ func run() error {
mux.Handle(
"POST /api/password",
middlewares.RateLimiter(
routes.CreatePassword(storage, maxPasswordLength, base64.StdEncoding),
routes.CreatePassword(storage, maxPasswordLength),
1*time.Minute,
5,
),
)
mux.Handle("GET /api/password/{id}", routes.GetPassword(storage, base64.StdEncoding))
mux.Handle("GET /api/password/{id}", routes.GetPassword(storage))
mux.Handle("HEAD /api/password/{id}", routes.HasPassword(storage))
if logRequests {

View file

@ -1,7 +1,6 @@
package routes
import (
"encoding/base64"
"encoding/json"
"net/http"
"time"
@ -9,7 +8,7 @@ import (
"git.1e99.eu/1e99/passed/storage"
)
func CreatePassword(store storage.Store, maxLength int, encoding *base64.Encoding) http.HandlerFunc {
func CreatePassword(store storage.Store, maxLength int) http.HandlerFunc {
return func(res http.ResponseWriter, req *http.Request) {
var reqBody struct {
// Go automatically decodes byte arrays using Base64

View file

@ -1,14 +1,13 @@
package routes
import (
"encoding/base64"
"encoding/json"
"net/http"
"git.1e99.eu/1e99/passed/storage"
)
func GetPassword(store storage.Store, encoding *base64.Encoding) http.HandlerFunc {
func GetPassword(store storage.Store) http.HandlerFunc {
return func(res http.ResponseWriter, req *http.Request) {
id := req.PathValue("id")
password, err := store.Get(id)