rest-api/articles.go

31 lines
584 B
Go
Raw Normal View History

2020-09-15 23:09:07 +02:00
package main
import (
"encoding/json"
2020-09-17 18:01:18 +02:00
"log"
2020-09-15 23:09:07 +02:00
"net/http"
)
// Article type
type Article struct {
Title string `json:"title"`
Description string `json:"description"`
Content string `json:"content"`
}
// Articles Collection
type Articles []Article
func getAllArticles() http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
articles := Articles{
Article{Title: "Test Title", Description: "Test Description", Content: "Hello content!"},
}
json.NewEncoder(w).Encode(articles)
2020-09-17 18:01:18 +02:00
log.Println("Served /articles")
2020-09-15 23:09:07 +02:00
}
return http.HandlerFunc(fn)
}