From 35c77899d8d1af5f1e3f24a17fb61cb359801cec Mon Sep 17 00:00:00 2001 From: gmemstr Date: Fri, 22 Sep 2017 08:50:03 -0700 Subject: [PATCH] Added JSON encoding to setup Uses native Go encoding/json package, plan to move config away from spf13/viper and admin login to SQL for multiple user support. --- assets/setup.html | 10 ++++++---- src/setup.go | 42 +++++++++++++++++++++++++++++++----------- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/assets/setup.html b/assets/setup.html index 6dff9f9..ecdc99d 100644 --- a/assets/setup.html +++ b/assets/setup.html @@ -11,16 +11,18 @@
- + - + - + - + + +
diff --git a/src/setup.go b/src/setup.go index 5f03da3..9dcc812 100644 --- a/src/setup.go +++ b/src/setup.go @@ -3,8 +3,20 @@ package main import ( "io/ioutil" "net/http" + // "fmt" + "encoding/json" + "strings" ) +type NewConfig struct { + Name string + Host string + Email string + Description string + Image string + PodcastUrl string +} + // Serve setup.html and config parameters func ServeSetup(w http.ResponseWriter, r *http.Request) { if r.Method == "GET" { @@ -16,16 +28,24 @@ func ServeSetup(w http.ResponseWriter, r *http.Request) { w.Write(data) } if r.Method == "POST" { - + r.ParseMultipartForm(32 << 20) + + // Parse form and convert to JSON + cnf := NewConfig{ + strings.Join(r.Form["podcastname"], ""), // Podcast name + strings.Join(r.Form["podcasthost"], ""), // Podcast host + strings.Join(r.Form["podcastemail"], ""), // Podcast host email + strings.Join(r.Form["podcastdescription"], ""), // Podcast Description + "", // Podcast image + "", // Podcast location + } + + b, err := json.Marshal(cnf) + if err != nil { + panic(err) + } + + ioutil.WriteFile("config.json", b, 0644) + w.Write([]byte("Done")) } } - -// Write JSON config to file -func WriteConfig() { - -} - -// Connect to SQL and create admin user -func CreateAdmin() { - -}