docs(pier,seaglass,sunrise,sunscreen,tide): compile README Go examples via src= (quick-261118-qsd)

This commit is contained in:
Jakub Zych
2026-11-18 20:04:47 +01:00
parent 6409837b0c
commit cd55a3980d
9 changed files with 449 additions and 69 deletions

View File

@@ -0,0 +1,35 @@
package sunrise_test
import (
"bytes"
"fmt"
"net/http"
"net/http/httptest"
"git.golem15.com/golem15/summercms/modules/sunrise"
)
func newScript(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
w.Header().Set("X-Content-Type-Options", "nosniff")
_, _ = w.Write(sunrise.Script())
}
func Example() {
srv := httptest.NewServer(http.HandlerFunc(newScript))
defer srv.Close()
resp, err := http.Get(srv.URL + "/new")
if err != nil {
fmt.Println(err)
return
}
defer resp.Body.Close()
var body bytes.Buffer
_, _ = body.ReadFrom(resp.Body)
fmt.Println(resp.StatusCode, resp.Header.Get("Content-Type"))
fmt.Println(bytes.Equal(body.Bytes(), sunrise.Script()), bytes.HasPrefix(body.Bytes(), []byte("#!")))
// Output:
// 200 text/plain; charset=utf-8
// true true
}