Skip to content

antony@notes:~/misc$ cat "Untitled-11.md"

Untitled

2023-01-08· misc

main.go

package main

import (
  "fmt"
  "net/http"
  "net/http/cgi"
)

func cgiMyDB(w http.ResponseWriter, r *http.Request) {
handler := cgi.Handler{Path: "/opt/www/cgi/mydb.sh"}
handler.ServeHTTP(w, r)
}

func cgiMyData(w http.ResponseWriter, r *http.Request) {
handler := cgi.Handler{Path: "/opt/www/cgi/mydata.sh"}
handler.ServeHTTP(w, r)
}

func cgiSetup(w http.ResponseWriter, r *http.Request) {
handler := cgi.Handler{Path: "/opt/www/cgi/mysetup.sh"}
handler.ServeHTTP(w, r)
}

func main() {
  static := http.FileServer(http.Dir("/opt/www"))
  http.Handle("/",static)

  http.HandleFunc("/db", cgiMyDB)
  http.HandleFunc("/data", cgiMyData)
  http.HandleFunc("/setup", cgiSetup)
  fmt.Println(":8080")
  http.ListenAndServe(":8080", nil)
}
  • mydb.sh 連線到 mysql Cluster
  • mydata.sh 連線到 大數據
  • mysetup.sh