Exemple #1
0
func HandleRouterCreateRouteRequest(conf *http.HttpConfiguration, context *http.HttpContext, r *rest.Request) (interface{}, error) {
		frontendname := r.PathParam("id")
		var data rjobs.AddRouteRequest
		if r.Body != nil {
			dec := json.NewDecoder(io.LimitReader(r.Body, 100*1024))
			if err := dec.Decode(&data); err != nil && err != io.EOF {
				fmt.Println("Error decoding json body - %s", err.Error())
				return nil, err
			}
		} else {
			// error
			return nil, jobs.SimpleError{jobs.ResponseInvalidRequest, fmt.Sprintf("Insufficient data to create route.")}
		}
		data.Frontend = frontendname
		return &rjobs.AddRouteRequest{data.Frontend, data.FrontendPath, data.BackendPath, data.Protocols, data.Endpoints}, nil
}
Exemple #2
0
func (e *Command) addRoute(cmd *cobra.Command, args []string) {
	fmt.Println("Adding route to frontend")
	fmt.Println(args)
	if len(args) != 1 {
		fmt.Println("Need one complex json argument to add route")
		return
	}
	var r rjobs.AddRouteRequest
	jerr := json.Unmarshal([]byte(args[0]), &r)
	if jerr != nil {
		fmt.Println("Error in unmarshalling input : %s", jerr.Error())
		return
	}
	if r.FrontendPath == "" {
		r.FrontendPath = "/"
	}
	if r.BackendPath == "" {
		r.BackendPath = "/"
	}

	t := e.Transport.Get()
	id, err := NewResourceLocator(t, "router", r.Frontend)
	if err != nil {
		fmt.Println("Json argument should have a valid 'Frontend' key. e.g.  { 'Frontend' : '<host>/<id>', Endpoints : [{ 'IP' : '<host_ip>', 'Port' : '<integer>'}] }")
		return
	}

	Executor{
		On: Locators{id},
		Serial: func(on Locator) JobRequest {
			return &rjobs.AddRouteRequest{
				Frontend:     on.(*ResourceLocator).Id,
				FrontendPath: r.FrontendPath,
				BackendPath:  r.BackendPath,
				Protocols:    r.Protocols,
				Endpoints:    r.Endpoints,
			}
		},
		Output:    os.Stdout,
		Transport: t,
	}.StreamAndExit()

	// router.AddRoute(r.Frontend, r.FrontendPath, r.BackendPath, r.Protocols, r.Endpoints)
}