Basic web server startup
This commit is contained in:
parent
ab54ace0d2
commit
497d2e3e27
5
dau.go
5
dau.go
@ -45,12 +45,11 @@ type Config struct {
|
|||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
config := parseOptions()
|
config := parseOptions()
|
||||||
|
|
||||||
checkPath(config.path)
|
checkPath(config.path)
|
||||||
checkUpdates()
|
|
||||||
|
|
||||||
web.Init()
|
web.Init()
|
||||||
|
|
||||||
|
checkUpdates()
|
||||||
|
|
||||||
log.Print("Waiting for images to appear in ", config.path)
|
log.Print("Waiting for images to appear in ", config.path)
|
||||||
// wander the path, forever
|
// wander the path, forever
|
||||||
for {
|
for {
|
||||||
|
35
web/web.go
35
web/web.go
@ -1,8 +1,35 @@
|
|||||||
package web
|
package web
|
||||||
|
|
||||||
// web server for the discord-auto-upload package
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
// Init - start the web server
|
func sayhelloName(w http.ResponseWriter, r *http.Request) {
|
||||||
func Init() {
|
r.ParseForm() // parse arguments, you have to call this by yourself
|
||||||
return
|
fmt.Println(r.Form) // print form information in server side
|
||||||
|
fmt.Println("path", r.URL.Path)
|
||||||
|
fmt.Println("scheme", r.URL.Scheme)
|
||||||
|
fmt.Println(r.Form["url_long"])
|
||||||
|
for k, v := range r.Form {
|
||||||
|
fmt.Println("key:", k)
|
||||||
|
fmt.Println("val:", strings.Join(v, ""))
|
||||||
|
}
|
||||||
|
fmt.Fprintf(w, "Response!") // send data to client side
|
||||||
|
}
|
||||||
|
|
||||||
|
// Init is great
|
||||||
|
func Init() {
|
||||||
|
go startWebServer()
|
||||||
|
}
|
||||||
|
|
||||||
|
func startWebServer() {
|
||||||
|
http.HandleFunc("/", sayhelloName) // set router
|
||||||
|
log.Print("Starting web server on http://localhost:9090")
|
||||||
|
err := http.ListenAndServe(":9090", nil) // set listen port
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("ListenAndServe: ", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user