Exemple #1
0
func (fs RouteFileStore) Get(id string) (*defines.Route, error) {
	file, err := os.Open(fs.Filename(id))
	if err != nil {
		return nil, err
	}
	route := new(defines.Route)
	if err = utils.Unmarshal(file, route); err != nil {
		return nil, err
	}
	if route.ID == "" {
		route.ID = id
	}
	return route, nil
}
Exemple #2
0
func InitLenz() {
	Attacher = NewAttachManager()
	Router = NewRouteManager(Attacher)
	Routefs = RouteFileStore(g.Config.Lenz.Routes)
	if len(g.Config.Lenz.Forwards) > 0 {
		logs.Debug("Lenz Routing all to", g.Config.Lenz.Forwards)
		target := defines.Target{Addrs: g.Config.Lenz.Forwards}
		route := defines.Route{ID: common.LENZ_DEFAULT, Target: &target}
		route.LoadBackends()
		Router.Add(&route)
	}
	if _, err := os.Stat(g.Config.Lenz.Routes); err == nil {
		logs.Debug("Loading and persisting routes in", g.Config.Lenz.Routes)
		logs.Assert(Router.Load(Routefs), "persistor")
	}
	logs.Info("Lenz initiated")
}
Exemple #3
0
func (rm *RouteManager) Add(route *defines.Route) error {
	rm.Lock()
	defer rm.Unlock()
	route.Closer = make(chan bool)
	route.Done = make(chan struct{})
	rm.routes[route.ID] = route
	go func() {
		logstream := make(chan *defines.Log)
		go Streamer(route, logstream)
		rm.attacher.Listen(route.Source, logstream, route.Closer)
		close(logstream)
	}()
	if rm.persistor != nil {
		if err := rm.persistor.Add(route); err != nil {
			logs.Info("Lenz Persistor:", err)
		}
	}
	return nil
}