This commit is contained in:
Jan-Lukas Else 2021-02-17 08:23:03 +01:00
parent 58f41085dd
commit 91788efe67
12 changed files with 17 additions and 24 deletions

View File

@ -1,4 +1,4 @@
FROM golang:1.15-alpine3.13 as build FROM golang:1.16-alpine3.13 as build
RUN apk add --no-cache git gcc musl-dev sqlite-dev RUN apk add --no-cache git gcc musl-dev sqlite-dev
ADD *.go /app/ ADD *.go /app/
ADD go.mod /app/ ADD go.mod /app/

View File

@ -8,10 +8,10 @@ import (
"encoding/pem" "encoding/pem"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"log" "log"
"net/http" "net/http"
"net/url" "net/url"
"os"
"regexp" "regexp"
"strings" "strings"
"sync" "sync"
@ -46,7 +46,7 @@ func initActivityPub() error {
p.apDelete() p.apDelete()
}) })
// Read key and prepare signing // Read key and prepare signing
pkfile, err := ioutil.ReadFile(appConfig.ActivityPub.KeyPath) pkfile, err := os.ReadFile(appConfig.ActivityPub.KeyPath)
if err != nil { if err != nil {
return err return err
} }

View File

@ -5,7 +5,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"log" "log"
"net/http" "net/http"
"net/url" "net/url"
@ -130,7 +130,7 @@ func apSendSigned(blogIri, to string, activity []byte) error {
return err return err
} }
if !apRequestIsSuccess(resp.StatusCode) { if !apRequestIsSuccess(resp.StatusCode) {
body, _ := ioutil.ReadAll(resp.Body) body, _ := io.ReadAll(resp.Body)
_ = resp.Body.Close() _ = resp.Body.Close()
return fmt.Errorf("signed request failed with status %d: %s", resp.StatusCode, string(body)) return fmt.Errorf("signed request failed with status %d: %s", resp.StatusCode, string(body))
} }

View File

@ -5,7 +5,6 @@ import (
"encoding/base64" "encoding/base64"
"encoding/json" "encoding/json"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"time" "time"
@ -44,7 +43,7 @@ func authMiddleware(next http.Handler) http.Handler {
// 3. Show login form // 3. Show login form
w.WriteHeader(http.StatusUnauthorized) w.WriteHeader(http.StatusUnauthorized)
h, _ := json.Marshal(r.Header.Clone()) h, _ := json.Marshal(r.Header.Clone())
b, _ := ioutil.ReadAll(io.LimitReader(r.Body, 2000000)) // Only allow 20 Megabyte b, _ := io.ReadAll(io.LimitReader(r.Body, 2000000)) // Only allow 20 Megabyte
_ = r.Body.Close() _ = r.Body.Close()
if len(b) == 0 { if len(b) == 0 {
// Maybe it's a form // Maybe it's a form

View File

@ -5,7 +5,6 @@ import (
"crypto/sha256" "crypto/sha256"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"strconv" "strconv"
@ -122,7 +121,7 @@ func getCache(key string, next http.Handler, r *http.Request) (item *cacheItem)
next.ServeHTTP(recorder, r) next.ServeHTTP(recorder, r)
// Cache values from recorder // Cache values from recorder
result := recorder.Result() result := recorder.Result()
body, _ := ioutil.ReadAll(result.Body) body, _ := io.ReadAll(result.Body)
_ = result.Body.Close() _ = result.Body.Close()
eTag := result.Header.Get("ETag") eTag := result.Header.Get("ETag")
if eTag == "" { if eTag == "" {

View File

@ -5,7 +5,6 @@ import (
"encoding/base64" "encoding/base64"
"encoding/json" "encoding/json"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"time" "time"
@ -28,7 +27,7 @@ func captchaMiddleware(next http.Handler) http.Handler {
// 2. Show Captcha // 2. Show Captcha
w.WriteHeader(http.StatusUnauthorized) w.WriteHeader(http.StatusUnauthorized)
h, _ := json.Marshal(r.Header.Clone()) h, _ := json.Marshal(r.Header.Clone())
b, _ := ioutil.ReadAll(io.LimitReader(r.Body, 2000000)) // Only allow 20 Megabyte b, _ := io.ReadAll(io.LimitReader(r.Body, 2000000)) // Only allow 20 Megabyte
_ = r.Body.Close() _ = r.Body.Close()
if len(b) == 0 { if len(b) == 0 {
// Maybe it's a form // Maybe it's a form

4
go.mod
View File

@ -1,6 +1,6 @@
module git.jlel.se/jlelse/GoBlog module git.jlel.se/jlelse/GoBlog
go 1.15 go 1.16
require ( require (
codeberg.org/jlelse/tinify v0.0.0-20200123222407-7fc9c21822b0 codeberg.org/jlelse/tinify v0.0.0-20200123222407-7fc9c21822b0
@ -54,7 +54,7 @@ require (
golang.org/x/mod v0.4.1 // indirect golang.org/x/mod v0.4.1 // indirect
golang.org/x/net v0.0.0-20210119194325-5f4716e94777 // indirect golang.org/x/net v0.0.0-20210119194325-5f4716e94777 // indirect
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a golang.org/x/sync v0.0.0-20201207232520-09787c993a3a
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c // indirect golang.org/x/sys v0.0.0-20210216224549-f992740a1bac // indirect
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf // indirect golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf // indirect
golang.org/x/text v0.3.5 // indirect golang.org/x/text v0.3.5 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect

4
go.sum
View File

@ -404,8 +404,8 @@ golang.org/x/sys v0.0.0-20200724161237-0e2f3a69832c/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c h1:VwygUrnw9jn88c4u8GD3rZQbqrP/tgas88tPUbBxQrk= golang.org/x/sys v0.0.0-20210216224549-f992740a1bac h1:9glrpwtNjBYgRpb67AZJKHfzj1stG/8BL5H7In2oTC4=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210216224549-f992740a1bac/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf h1:MZ2shdL+ZM/XzY3ZGOnh4Nlpnxz5GSOhOmtHo3iPU6M= golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf h1:MZ2shdL+ZM/XzY3ZGOnh4Nlpnxz5GSOhOmtHo3iPU6M=

View File

@ -7,7 +7,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"mime" "mime"
"mime/multipart" "mime/multipart"
"net/http" "net/http"
@ -147,7 +146,7 @@ func tinify(url string, config *configMicropubMedia) (location string, err error
}); err != nil { }); err != nil {
return "", err return "", err
} }
tmpFile, err := ioutil.TempFile("", "tiny-*."+fileExtension) tmpFile, err := os.CreateTemp("", "tiny-*."+fileExtension)
if err != nil { if err != nil {
return "", err return "", err
} }
@ -200,7 +199,7 @@ func shortPixel(url string, config *configMicropubMedia) (location string, err e
} else if resp.StatusCode != http.StatusOK { } else if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("failed to compress image, status code %d", resp.StatusCode) return "", fmt.Errorf("failed to compress image, status code %d", resp.StatusCode)
} }
tmpFile, err := ioutil.TempFile("", "tiny-*."+fileExtension) tmpFile, err := os.CreateTemp("", "tiny-*."+fileExtension)
if err != nil { if err != nil {
return "", err return "", err
} }

View File

@ -6,7 +6,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"html/template" "html/template"
"io/ioutil"
"log" "log"
"net/http" "net/http"
"os" "os"
@ -186,7 +185,7 @@ func initRendering() error {
}, },
"jsonFile": func(filename string) *map[string]interface{} { "jsonFile": func(filename string) *map[string]interface{} {
parsed := &map[string]interface{}{} parsed := &map[string]interface{}{}
content, err := ioutil.ReadFile(filename) content, err := os.ReadFile(filename)
if err != nil { if err != nil {
return nil return nil
} }

View File

@ -3,7 +3,6 @@ package main
import ( import (
"crypto/sha1" "crypto/sha1"
"fmt" "fmt"
"io/ioutil"
"mime" "mime"
"net/http" "net/http"
"os" "os"
@ -42,7 +41,7 @@ func initTemplateAssets() (err error) {
} }
func compileAsset(name string) (string, error) { func compileAsset(name string) (string, error) {
originalContent, err := ioutil.ReadFile(name) originalContent, err := os.ReadFile(name)
if err != nil { if err != nil {
return "", err return "", err
} }

View File

@ -1,7 +1,6 @@
package main package main
import ( import (
"io/ioutil"
"os" "os"
"path" "path"
@ -22,7 +21,7 @@ func initTemplateStrings() error {
} }
for _, variant := range variants { for _, variant := range variants {
variantStrings := map[string]string{} variantStrings := map[string]string{}
fileContent, err := ioutil.ReadFile(path.Join(stringsDir, variant+variantFileExt)) fileContent, err := os.ReadFile(path.Join(stringsDir, variant+variantFileExt))
if err != nil { if err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
continue continue