package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
)
type Article struct {
Title string `json:"Title"`
Author string `json:"Autor"`
Link string `json:"Link"`
}
var articles = []Article{
{
Title: "Python Intermediate and Advanced 101",
Author: "Arkaprabha Majumdar",
Link: "https://www.amazon.com/dp/B089KVK23P"},
{
Title: "R programming Advanced",
Author: "Arkaprabha Majumdar",
Link: "https://www.amazon.com/dp/B089WH12CR"},
{
Title: "R programming Fundamentals",
Author: "Arkaprabha Majumdar",
Link: "https://www.amazon.com/dp/B089S58WWG"},
}
func homePage(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Welcome to the HomePage!")
fmt.Println("Endpoint Hit: homePage")
}
func returnAllArticles(w http.ResponseWriter, r *http.Request) {
fmt.Println("Endpoint Hit: returnAllArticles")
json.NewEncoder(w).Encode(articles)
}
func handleRequests() {
http.HandleFunc("/", homePage)
http.HandleFunc("/articles", returnAllArticles)
log.Fatal(http.ListenAndServe(":8000", nil))
}
func main() {
handleRequests()
}