grim/cerestial

initial commit that just handles moon phases

17 months ago, Gary Kramlich
4cca2f719ba8
Parents
Children 06d4d14f0ce9
initial commit that just handles moon phases
  • +3 -0
    .hgignore
  • +5 -0
    go.mod
  • +2 -0
    go.sum
  • +27 -0
    main.go
  • --- /dev/null Thu Jan 01 00:00:00 1970 +0000
    +++ b/.hgignore Thu Dec 08 01:47:05 2022 -0600
    @@ -0,0 +1,3 @@
    +syntax: glob
    +cerestial
    +
    --- /dev/null Thu Jan 01 00:00:00 1970 +0000
    +++ b/go.mod Thu Dec 08 01:47:05 2022 -0600
    @@ -0,0 +1,5 @@
    +module hg.sr.ht/~grim/cerestial
    +
    +go 1.19
    +
    +require github.com/janczer/goMoonPhase v0.0.0-20210411203237-6c61017953a8
    --- /dev/null Thu Jan 01 00:00:00 1970 +0000
    +++ b/go.sum Thu Dec 08 01:47:05 2022 -0600
    @@ -0,0 +1,2 @@
    +github.com/janczer/goMoonPhase v0.0.0-20210411203237-6c61017953a8 h1:Dm5ZV6OiMV+c0NcjZZNE/qdyyWLSGP2aI4mt4vBWMS8=
    +github.com/janczer/goMoonPhase v0.0.0-20210411203237-6c61017953a8/go.mod h1:cP58cMQH4tMoeknficHktMZj5QraEnMIMcR0I9EzuzU=
    --- /dev/null Thu Jan 01 00:00:00 1970 +0000
    +++ b/main.go Thu Dec 08 01:47:05 2022 -0600
    @@ -0,0 +1,27 @@
    +package main
    +
    +import (
    + "encoding/json"
    + "net/http"
    + "time"
    +
    + moonphase "github.com/janczer/goMoonPhase"
    +)
    +
    +func moon_handler(w http.ResponseWriter, r *http.Request) {
    + data := map[string]any{
    + "moon": map[string]any{
    + "phase": moonphase.New(time.Now()).PhaseName(),
    + },
    + }
    +
    + w.Header().Set("Content-Type", "application/json")
    + json.NewEncoder(w).Encode(data)
    +}
    +
    +func main() {
    + mux := http.NewServeMux()
    + mux.Handle("/moon", http.HandlerFunc(moon_handler))
    +
    + http.ListenAndServe(":3000", mux)
    +}