mirror of
https://github.com/NotAShelf/catApi.git
synced 2026-01-18 00:08:40 +00:00
Compare commits
No commits in common. "c8e8f5467a030cfa5d87168b8bf0b11e2dce167e" and "d377c9419de1e11553bd1d79cfe122250abcb802" have entirely different histories.
c8e8f5467a
...
d377c9419d
5 changed files with 8 additions and 29 deletions
2
.github/workflows/go.yml
vendored
2
.github/workflows/go.yml
vendored
|
|
@ -18,7 +18,7 @@ jobs:
|
||||||
go-version: "1.23"
|
go-version: "1.23"
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: go build -v .
|
run: go build -v ./..
|
||||||
|
|
||||||
- name: Upload a Build Artifact
|
- name: Upload a Build Artifact
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
|
|
|
||||||
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -17,6 +17,3 @@ yarn-error.log
|
||||||
# Build Artifacts
|
# Build Artifacts
|
||||||
result*
|
result*
|
||||||
catApi
|
catApi
|
||||||
|
|
||||||
# Production Config
|
|
||||||
config.yml
|
|
||||||
|
|
|
||||||
2
config.yaml
Normal file
2
config.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
server:
|
||||||
|
port: "3000"
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
server:
|
|
||||||
port: "3000"
|
|
||||||
|
|
||||||
site:
|
|
||||||
title: "Cat Gallery"
|
|
||||||
header: "Cat Gallery"
|
|
||||||
24
main.go
24
main.go
|
|
@ -18,8 +18,6 @@ import (
|
||||||
|
|
||||||
var images []string
|
var images []string
|
||||||
var logger = logrus.New()
|
var logger = logrus.New()
|
||||||
var title string
|
|
||||||
var header string
|
|
||||||
var port string
|
var port string
|
||||||
|
|
||||||
// Cache for image list, it should expire every 10 minutes
|
// Cache for image list, it should expire every 10 minutes
|
||||||
|
|
@ -37,7 +35,7 @@ var tmpl = template.Must(template.New("index").Parse(`
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>{{.Title}}</title>
|
<title>Image Gallery</title>
|
||||||
<style>
|
<style>
|
||||||
body { font-family: Arial, sans-serif; text-align: center; }
|
body { font-family: Arial, sans-serif; text-align: center; }
|
||||||
.gallery {
|
.gallery {
|
||||||
|
|
@ -61,7 +59,7 @@ var tmpl = template.Must(template.New("index").Parse(`
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>{{.Header}}</h1>
|
<h1>Image Gallery</h1>
|
||||||
<div class="gallery">
|
<div class="gallery">
|
||||||
{{range $index, $img := .Images}}
|
{{range $index, $img := .Images}}
|
||||||
<a href="/api/id?id={{$index}}">
|
<a href="/api/id?id={{$index}}">
|
||||||
|
|
@ -81,8 +79,9 @@ func init() {
|
||||||
|
|
||||||
// Set the log level (info, warning, error, etc.)
|
// Set the log level (info, warning, error, etc.)
|
||||||
logger.SetLevel(logrus.InfoLevel)
|
logger.SetLevel(logrus.InfoLevel)
|
||||||
|
}
|
||||||
|
|
||||||
// Load config
|
func main() {
|
||||||
viper.SetConfigName("config") // name of config file (without extension)
|
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.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
|
viper.AddConfigPath(".") // path to look for the config file in
|
||||||
|
|
@ -94,12 +93,6 @@ func init() {
|
||||||
port = viper.GetString("server.port")
|
port = viper.GetString("server.port")
|
||||||
images = getImages()
|
images = getImages()
|
||||||
|
|
||||||
// Load site settings (title and header)
|
|
||||||
title = viper.GetString("site.title")
|
|
||||||
header = viper.GetString("site.header")
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
// Add request logging middleware
|
// Add request logging middleware
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.HandleFunc("/", homeHandler)
|
mux.HandleFunc("/", homeHandler)
|
||||||
|
|
@ -143,18 +136,11 @@ func getImages() []string {
|
||||||
return images
|
return images
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func homeHandler(w http.ResponseWriter, r *http.Request) {
|
func homeHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "text/html")
|
w.Header().Set("Content-Type", "text/html")
|
||||||
tmpl.Execute(w, struct {
|
tmpl.Execute(w, struct {
|
||||||
Title string
|
|
||||||
Header string
|
|
||||||
Images []string
|
Images []string
|
||||||
}{
|
}{Images: getCachedImages()})
|
||||||
Title: title,
|
|
||||||
Header: header,
|
|
||||||
Images: getCachedImages(),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func idHandler(w http.ResponseWriter, r *http.Request) {
|
func idHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue