grim/cerestial
Clone
Summary
Browse
Changes
Graph
Add a .reviewboardrc
default
tip
18 months ago, Gary Kramlich
da5e9416581b
Add a .reviewboardrc
package
main
import
(
"encoding/json"
"math"
"net/http"
"time"
"github.com/dyindude/moonphase"
)
func
moon_handler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
moon
:=
moonphase
.
New
(
time
.
Now
())
data
:=
map
[
string
]
any
{
"moon"
:
map
[
string
]
any
{
"phase"
:
moon
.
PhaseName
(),
"illumination"
:
math
.
Round
(
100000
*
moon
.
Illumination
())
/
1000
,
"age"
:
math
.
Round
(
100
*
moon
.
Age
())
/
100
,
"distance_km"
:
moon
.
Distance
(),
"zodiac"
:
map
[
string
]
any
{
"tropical"
:
moon
.
ZodiacSignTropical
(),
// sidereal has to be last because it modifies the moon object.
"sidereal"
:
moon
.
ZodiacSignSidereal
(),
},
},
}
w
.
Header
().
Set
(
"Content-Type"
,
"application/json"
)
json
.
NewEncoder
(
w
).
Encode
(
data
)
}
func
main
()
{
mux
:=
http
.
NewServeMux
()
api
:=
http
.
NewServeMux
()
mux
.
Handle
(
"/api/"
,
http
.
StripPrefix
(
"/api"
,
api
))
v1
:=
http
.
NewServeMux
()
api
.
Handle
(
"/v1/"
,
http
.
StripPrefix
(
"/v1"
,
v1
))
v1
.
Handle
(
"/moon"
,
http
.
HandlerFunc
(
moon_handler
))
http
.
ListenAndServe
(
":3000"
,
mux
)
}