Exemple #1
0
func (d *LocationDirective) Apply(c api.Server, items map[string]interface{}) (bool, error) {
	if err := api.Remarshal(items, d); err != nil {
		return false, err
	}
	if d.Location == "" {
		return false, errors.New("location directive missing path")
	}
	r := c.Route(strings.TrimSpace(d.Location))
	r = d.Match.SetRoute(r)
	r = d.SetContentHandler(c, r)
	return false, nil
}
Exemple #2
0
func (d *HttpDirective) Apply(c api.Server, items map[string]interface{}) (bool, error) {
	if err := api.Remarshal(items, d); err != nil {
		log.Error("directive.http.remarshal", "error", err)
		return false, err
	}
	host, cf, kf := d.Http, d.CertFile, d.KeyFile
	if host == "" {
		host = d.Https
	}
	// mb check cert and key files exist and are readable
	c.Endpoint(host, cf, kf, host == d.Https)
	return false, nil
}
Exemple #3
0
func (d *InitDirective) Apply(c api.Server, items map[string]interface{}) (bool, error) {
	s, ok := items["init"].(string)
	if !ok {
		return false, errors.New("init value not string")
	}

	sz := strings.TrimSpace(s)
	if bs, err := ioutil.ReadFile(sz); err == nil {
		s = string(bs)
	} else {
		if !strings.HasSuffix(err.Error(), "no such file or directory") {
			log.Info("directive.init.readfile", "error", err)
		}
	}

	c.OnInit(func(L *lua.LState) error {
		L.SetGlobal("motd", lua.LString("hello, world oninit"))
		return nil
	})

	return false, nil
}
Exemple #4
0
func (d *LocationDirective) SetContentHandler(c api.Server, r *mux.Route) *mux.Route {
	//
	r = r.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		L := c.NewLuaState(w, r)
		defer L.Close()

		// if file, read once and set string
		err := L.DoFile("test.lua")

		// if string, set string

		// if value in handler map, set handler

		// if values in handler map, set handlers

		if err != nil {
			log.Error("server.request.lua", "path", r.URL, "error", err)
		}

	})
	return r
}