package main import ( "bytes" "errors" "fmt" "html/template" "io" "net/http" "path/filepath" "regexp" "strings" "sync" ) type NoMoreError struct { Err error } func (e *NoMoreError) Error() string { return "no more images available" } type Image struct { Path string Index int } type ImageViewModel struct { Title string Images []Image } type Server struct { PrevViewModel *ImageViewModel CurrViewModel *ImageViewModel NextViewModel *ImageViewModel ImageBuffers map[string]*bytes.Buffer NextSubUrl string CurrSubUrl string PrevSubUrl string IsFirst bool IsLast bool // I'm not even sure if this helps // If you press next and then prev too fast you still lock yourself out NextReady chan bool PrevReady chan bool } func getImageList(html string) ([]string, error) { reg, err := regexp.Compile(` 300 { return "", errors.New("could not get html") } defer func(Body io.ReadCloser) { err := Body.Close() if err != nil { fmt.Printf("Could not close body because: %v\n", err) } }(resp.Body) all, err := io.ReadAll(resp.Body) if err != nil { return "", err } h := string(all) return h, nil } func getNext(html string) (subUrl string, err error) { reg, err := regexp.Compile(`