func()

in whisk/rule.go [195:228]


func (s *RuleService) SetState(ruleName string, state string) (*Rule, *http.Response, error) {
	state = strings.ToLower(state)
	if state != "active" && state != "inactive" {
		errStr := wski18n.T("Internal error. Invalid state option '{{.state}}'. Valid options are \"active\" and \"inactive\".",
			map[string]interface{}{"state": state})
		werr := MakeWskError(errors.New(errStr), EXIT_CODE_ERR_GENERAL, DISPLAY_MSG, DISPLAY_USAGE)
		return nil, nil, werr
	}

	// Encode resource name as a path (with no query params) before inserting it into the URI
	// This way any '?' chars in the name won't be treated as the beginning of the query params
	ruleName = (&url.URL{Path: ruleName}).String()
	route := fmt.Sprintf("rules/%s", ruleName)

	ruleState := &Rule{Status: state}

	req, err := s.client.NewRequest("POST", route, ruleState, IncludeNamespaceInUrl)
	if err != nil {
		Debug(DbgError, "http.NewRequest(POST, %s); error: '%s'\n", route, err)
		errStr := wski18n.T("Unable to create HTTP request for POST '{{.route}}': {{.err}}",
			map[string]interface{}{"route": route, "err": err})
		werr := MakeWskErrorFromWskError(errors.New(errStr), err, EXIT_CODE_ERR_GENERAL, DISPLAY_MSG, NO_DISPLAY_USAGE)
		return nil, nil, werr
	}

	r := new(Rule)
	resp, err := s.client.Do(req, &r, ExitWithSuccessOnTimeout)
	if err != nil {
		Debug(DbgError, "s.client.Do() error - HTTP req %s; error: '%s'\n", req.URL.String(), err)
		return nil, resp, err
	}

	return r, resp, nil
}