mirror of
https://github.com/foomo/gotsrpc.git
synced 2025-10-16 12:35:35 +00:00
45 lines
721 B
Go
45 lines
721 B
Go
package main
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/foomo/gotsrpc/demo"
|
|
)
|
|
|
|
type Demo struct {
|
|
proxy *demo.ServiceGoTSRPCProxy
|
|
}
|
|
|
|
func (d *Demo) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
switch r.URL.Path {
|
|
case "/demo.js":
|
|
serveFile("demo.js", w)
|
|
case "/":
|
|
serveFile("index.html", w)
|
|
default:
|
|
switch true {
|
|
case strings.HasPrefix(r.URL.Path, "/service"):
|
|
d.proxy.ServeHTTP(w, r)
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
func serveFile(name string, w http.ResponseWriter) {
|
|
index, err := ioutil.ReadFile(name)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
w.Write(index)
|
|
|
|
}
|
|
|
|
func main() {
|
|
d := &Demo{
|
|
proxy: demo.NewServiceGoTSRPCProxy(&demo.Service{}, "/service"),
|
|
}
|
|
http.ListenAndServe(":8080", d)
|
|
}
|