mirror of
https://github.com/gmemstr/pogo.git
synced 2024-09-20 01:31:09 +01:00
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.
This commit is contained in:
parent
99cb95d51b
commit
35c77899d8
|
@ -11,16 +11,18 @@
|
|||
<form action="setup" method="post" class="setupform">
|
||||
|
||||
<label for="podcastname">Podcast Name</label>
|
||||
<input type="text" id="podcastname">
|
||||
<input type="text" id="podcastname" name="podcastname">
|
||||
|
||||
<label for="podcasthost">Podcast Host</label>
|
||||
<input type="text" id="podcasthost">
|
||||
<input type="text" id="podcasthost" name="podcasthost">
|
||||
|
||||
<label for="podcastemail">Podcast Email</label>
|
||||
<input type="text" id="podcastemail">
|
||||
<input type="text" id="podcastemail" name="podcastemail">
|
||||
|
||||
<label for="podcastdescription">Podcast Description</label>
|
||||
<textarea name="" id="podcastdescription" cols="75" rows="5"></textarea>
|
||||
<textarea name="" id="podcastdescription" name="podcastdescription" cols="75" rows="5"></textarea>
|
||||
|
||||
<input type="submit" value="Submit">
|
||||
|
||||
</form>
|
||||
|
||||
|
|
40
src/setup.go
40
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() {
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue