func()

in whisk/action.go [211:236]


func (s *ActionService) Insert(action *Action, overwrite bool) (*Action, *http.Response, error) {
	// 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
	actionName := (&url.URL{Path: action.Name}).String()
	route := fmt.Sprintf("actions/%s?overwrite=%t", actionName, overwrite)
	Debug(DbgInfo, "Action insert route: %s\n", route)

	req, err := s.client.NewRequest("PUT", route, action, IncludeNamespaceInUrl)
	if err != nil {
		Debug(DbgError, "http.NewRequest(PUT, %s, %#v) error: '%s'\n", route, action, err)
		errMsg := wski18n.T("Unable to create HTTP request for PUT '{{.route}}': {{.err}}",
			map[string]interface{}{"route": route, "err": err})
		whiskErr := MakeWskErrorFromWskError(errors.New(errMsg), err, EXIT_CODE_ERR_NETWORK, DISPLAY_MSG,
			NO_DISPLAY_USAGE)
		return nil, nil, whiskErr
	}

	a := new(Action)
	resp, err := s.client.Do(req, &a, 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 a, resp, nil
}