68 lines
2.1 KiB
Go
68 lines
2.1 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
)
|
|
|
|
// ---------- HTTP Handlers ----------
|
|
|
|
func HelloHandler(w http.ResponseWriter, r *http.Request) {
|
|
if r.URL.Path != "/hello" {
|
|
http.Error(w, "404 not found", http.StatusNotFound)
|
|
return
|
|
}
|
|
if r.Method != "GET" {
|
|
http.Error(w, "method is not supported", http.StatusNotFound)
|
|
return
|
|
}
|
|
fmt.Fprintf(w, "Hello You")
|
|
}
|
|
|
|
func Home(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "./static/index.html") }
|
|
func Infra(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "./static/infra.html") }
|
|
func Finance(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "./static/finance.html") }
|
|
func Cinema(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "./static/cinema.html") }
|
|
func Engine(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "./static/engine.html") }
|
|
func Portfolio(w http.ResponseWriter, r *http.Request) {
|
|
http.ServeFile(w, r, "./static/portfolio.html")
|
|
}
|
|
func About(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "./static/about.html") }
|
|
|
|
func Styles(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "./static/styles.css") }
|
|
func Styles2(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "./static/styles2.css") }
|
|
|
|
// ---------- Main ----------
|
|
|
|
func main() {
|
|
port := flag.String("port", "8081", "port to listen on")
|
|
flag.Parse()
|
|
|
|
http.HandleFunc("/styles.css", Styles)
|
|
http.HandleFunc("/styles2.css", Styles2)
|
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|
if r.URL.Path != "/" {
|
|
http.Redirect(w, r, "/", http.StatusFound)
|
|
return
|
|
}
|
|
About(w, r)
|
|
})
|
|
//http.HandleFunc("/portfolio", Portfolio)
|
|
http.HandleFunc("/infra", Infra)
|
|
http.HandleFunc("/finance", Finance)
|
|
http.HandleFunc("/cinema", Cinema)
|
|
http.HandleFunc("/engine", Engine)
|
|
http.HandleFunc("/portfolio", Portfolio)
|
|
|
|
http.HandleFunc("/git", func(w http.ResponseWriter, r *http.Request) {
|
|
http.Redirect(w, r, "https://git.samantha42.xyz", http.StatusFound)
|
|
})
|
|
|
|
fmt.Printf("running on http://localhost:%s/\n", *port)
|
|
if err := http.ListenAndServe(":"+*port, nil); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|