예제 #1
0
파일: routes.go 프로젝트: jcantrill/geard
func (j AddAliasRequest) Execute(resp jobs.Response) {
	value, ok := router.GlobalRoutes[j.Frontend]
	if ok {
		router.AddAlias(j.Alias, value.Name)
	} else {
		router.CreateFrontend(j.Frontend, j.Alias)
	}
	resp.Success(jobs.ResponseOk)
}
예제 #2
0
파일: routes.go 프로젝트: jcantrill/geard
func (j CreateFrontendRequest) Execute(resp jobs.Response) {
	value, ok := router.GlobalRoutes[j.Frontend]
	if !ok {
		router.CreateFrontend(j.Frontend, j.Alias)
	} else {
		log.Printf("Error : Frontend %s already exists.", value.Name)
	}
	resp.Success(jobs.ResponseOk)
}
예제 #3
0
파일: cmd.go 프로젝트: pombredanne/geard
func (e *Command) test(cmd *cobra.Command, args []string) {
	fmt.Println("Router testing.")
	frontendname := "geard-router-test"
	alias := "www.alias.com"
	router.CreateFrontend(frontendname, alias)

	// empty the global datastucture and re-read to confirm that correct output has been generated
	router.GlobalRoutes = nil
	router.ReadRoutes()
	frontend, ok := router.GlobalRoutes[frontendname]
	if !ok {
		fmt.Println("Test failed. Frontend created was not persisted.")
		return
	}
	if frontend.HostAliases[0] != alias {
		fmt.Println("Test failed. Frontend created did not persist its alias.")
		return
	}

	// create a route
	s := router.Endpoint{}
	s.IP = "localhost"
	s.Port = "4001"
	endpoints := make([]router.Endpoint, 1)
	endpoints[0] = s
	router.AddRoute(frontendname, "", "", nil, endpoints)

	// empty the db again and check for routes
	router.GlobalRoutes = nil
	router.ReadRoutes()
	frontend, ok = router.GlobalRoutes[frontendname]
	if !ok {
		fmt.Println("Test failed. Frontend created was not persisted.")
		return
	}
	if len(frontend.EndpointTable) != 1 {
		fmt.Println("Test failed. Created one route, but %d found.", len(frontend.EndpointTable))
		return
	}
	for _, ep := range frontend.EndpointTable {
		if ep.IP != "localhost" || ep.Port != "4001" {
			fmt.Println("Test failed. Created one route, but invalid values were persisted.", len(frontend.EndpointTable))
			return
		}
	}

	// good so far, now delete the testfrontend
	router.DeleteFrontend(frontendname)
	_, ok = router.GlobalRoutes[frontendname]
	if ok {
		fmt.Println("Test failed. Frontend deletion does not actually remove the frontend from the routing table.")
	}

	// all good
	fmt.Println(router.PrintRoutes())
}