Exemple #1
0
// tdir = fe templates dir
// sdir = fe static files dir
func MakeFrontEnd(
	tdir, sdir string,
	addr string,
	allow string,
	bank sys.Bank,
	vault vault.Vault,
	myid sys.Id) (*FrontEnd, os.Error) {

	fe := &FrontEnd{
		tdir:     tdir,
		sdir:     sdir,
		bank:     bank,
		vault:    vault,
		adminURL: "http://a." + sys.Host,
		myURL:    sys.MakeURL("", myid, ""),
	}
	err := fe.loadTmpls()
	if err != nil {
		return nil, err
	}
	l, err := net.Listen("tcp", addr)
	if err != nil {
		return nil, err
	}
	fe.wwwclient = http.NewAsyncClient(30e9, 2, 3, 60)
	fe.server = http.NewAsyncServer(l, 20e9, 100)
	fe.server.SetAllowHosts(http.MakeAllowHosts(allow))
	go fe.serveLoop()
	return fe, nil
}
Exemple #2
0
func (fe *FrontEnd) replyRoot() *http.Response {
	friends := fe.bank.Enumerate()
	var u bytes.Buffer
	u.WriteString("<ul>")
	i := 0
	for _, f := range friends {
		if f.IsOnline() {
			u.WriteString("<li><div class=\"ok\"><a href=\"" +
				sys.MakeURL("", *f.GetId(), "") + "\">" + f.GetName() +
				"</a></div></li>")
		} else {
			u.WriteString("<li><div class=\"nop\">" + f.GetName() + "</div></li>")
		}
		i++
	}
	u.WriteString("</ul>")
	data := rootData{
		MyURL:    fe.myURL,
		AdminURL: fe.adminURL,
		Links:    u.String(),
	}
	var w bytes.Buffer
	err := fe.tmplRoot.Execute(&data, &w)
	if err != nil {
		return newRespServiceUnavailable()
	}

	pdata := pageData{
		Title:      sys.Name + " &mdash; Start page",
		CSSLinks:   []string{"root.css"},
		JSLinks:    []string{"root.js"},
		GridLayout: "",
		Content:    w.String(),
	}
	var w2 bytes.Buffer
	err = fe.tmplPage.Execute(&pdata, &w2)
	if err != nil {
		return newRespServiceUnavailable()
	}
	return buildResp(w2.String())
}
Exemple #3
0
func (fe *FrontEnd) replyAPILive(args map[string][]string) *http.Response {
	var w bytes.Buffer
	fmt.Fprintf(&w, "<ul>")
	friends := fe.bank.Enumerate()
	for _, f := range friends {
		if f.IsOnline() {
			fmt.Fprintf(&w, "<li><div class=\"ok\"><a href=\""+
				sys.MakeURL("", *f.GetId(), "")+
				"\">"+f.GetName()+"</a></div></li>")
		} else {
			fmt.Fprintf(&w, "<li><div class=\"nop\">"+f.GetName()+"</div></li>")
		}
	}
	fmt.Fprintf(&w, "</ul>")
	r := &apiLiveResult{w.String()}
	jb, err := json.Marshal(r)
	if err != nil {
		return newRespServiceUnavailable()
	}
	return buildResp(string(jb))
}