Compare commits

..

No commits in common. "c8e8f5467a030cfa5d87168b8bf0b11e2dce167e" and "d377c9419de1e11553bd1d79cfe122250abcb802" have entirely different histories.

5 changed files with 8 additions and 29 deletions

View file

@ -18,7 +18,7 @@ jobs:
go-version: "1.23"
- name: Build
run: go build -v .
run: go build -v ./..
- name: Upload a Build Artifact
uses: actions/upload-artifact@v4

3
.gitignore vendored
View file

@ -17,6 +17,3 @@ yarn-error.log
# Build Artifacts
result*
catApi
# Production Config
config.yml

2
config.yaml Normal file
View file

@ -0,0 +1,2 @@
server:
port: "3000"

View file

@ -1,6 +0,0 @@
server:
port: "3000"
site:
title: "Cat Gallery"
header: "Cat Gallery"

24
main.go
View file

@ -18,8 +18,6 @@ import (
var images []string
var logger = logrus.New()
var title string
var header string
var port string
// Cache for image list, it should expire every 10 minutes
@ -37,7 +35,7 @@ var tmpl = template.Must(template.New("index").Parse(`
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{.Title}}</title>
<title>Image Gallery</title>
<style>
body { font-family: Arial, sans-serif; text-align: center; }
.gallery {
@ -61,7 +59,7 @@ var tmpl = template.Must(template.New("index").Parse(`
</style>
</head>
<body>
<h1>{{.Header}}</h1>
<h1>Image Gallery</h1>
<div class="gallery">
{{range $index, $img := .Images}}
<a href="/api/id?id={{$index}}">
@ -81,8 +79,9 @@ func init() {
// Set the log level (info, warning, error, etc.)
logger.SetLevel(logrus.InfoLevel)
}
// Load config
func main() {
viper.SetConfigName("config") // name of config file (without extension)
viper.SetConfigType("yaml") // REQUIRED if the config file does not have the extension in the name
viper.AddConfigPath(".") // path to look for the config file in
@ -94,12 +93,6 @@ func init() {
port = viper.GetString("server.port")
images = getImages()
// Load site settings (title and header)
title = viper.GetString("site.title")
header = viper.GetString("site.header")
}
func main() {
// Add request logging middleware
mux := http.NewServeMux()
mux.HandleFunc("/", homeHandler)
@ -143,18 +136,11 @@ func getImages() []string {
return images
}
func homeHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html")
tmpl.Execute(w, struct {
Title string
Header string
Images []string
}{
Title: title,
Header: header,
Images: getCachedImages(),
})
}{Images: getCachedImages()})
}
func idHandler(w http.ResponseWriter, r *http.Request) {