feat: Replace data fillcontent with custom reader

This commit is contained in:
Richard Hillmann
2022-06-16 17:36:08 +02:00
committed by GitHub
parent 12d9acfdb3
commit 2d6ebedb0f
5 changed files with 151 additions and 19 deletions

19
app.go
View File

@ -1,7 +1,6 @@
package main
import (
"bytes"
"crypto/tls"
"crypto/x509"
"encoding/json"
@ -181,7 +180,7 @@ func dataHandler(w http.ResponseWriter, r *http.Request) {
attachment = false
}
content := fillContent(size)
content := &contentReader{size: size}
if attachment {
w.Header().Set("Content-Disposition", "Attachment")
@ -311,22 +310,6 @@ func healthHandler(w http.ResponseWriter, req *http.Request) {
}
}
func fillContent(length int64) io.ReadSeeker {
charset := "-ABCDEFGHIJKLMNOPQRSTUVWXYZ"
b := make([]byte, length)
for i := range b {
b[i] = charset[i%len(charset)]
}
if length > 0 {
b[0] = '|'
b[length-1] = '|'
}
return bytes.NewReader(b)
}
func getEnv(key, fallback string) string {
value := os.Getenv(key)
if len(value) == 0 {