Create and open DB
This commit is contained in:
37
webadmin/main.go
Normal file
37
webadmin/main.go
Normal file
@ -0,0 +1,37 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
|
||||
"github.com/pkg/browser"
|
||||
)
|
||||
|
||||
func handleHome(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, "<h1>Hello Peachy!</h1>")
|
||||
}
|
||||
|
||||
func run() error {
|
||||
listener, err := net.Listen("tcp", ":0")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
port := listener.Addr().(*net.TCPAddr).Port
|
||||
|
||||
homeURL := fmt.Sprintf("http://localhost:%d", port)
|
||||
err = browser.OpenURL(homeURL)
|
||||
if err != nil {
|
||||
fmt.Printf("I couldn't open the browser automatically.\nDo it yourself, then go to %s.", homeURL)
|
||||
}
|
||||
|
||||
return http.Serve(listener, http.HandlerFunc(handleHome))
|
||||
}
|
||||
|
||||
func main() {
|
||||
err := run()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user