本文整理匯總了Golang中github.com/facebookgo/stackerr.Wrap函數的典型用法代碼示例。如果您正苦於以下問題:Golang Wrap函數的具體用法?Golang Wrap怎麽用?Golang Wrap使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Wrap函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: AddDir
// AddDir adds a directory to be watched, returning an error if any.
// It allows a filter to be specified on which files to watch.
// It also allows recursive watching.
func (fw *FileSystemWatcher) AddDir(path, pattern string, ops Op, recursive bool) error {
// Add the given path to be watched. addDir will perform checking for us to
// ensure that the path really is a directory.
err := fw.addDir(path, pattern, ops)
if err != nil {
return stackerr.Wrap(err)
}
if recursive {
err = filepath.Walk(path, func(p string, info os.FileInfo, err error) error {
if info.IsDir() {
// Subdirectories inherit the filename pattern and ops from the parent.
if e := fw.addDir(p, pattern, ops); err != nil {
return stackerr.Wrap(e)
}
}
return nil
})
if err != nil {
return err
}
}
return nil
}
示例2: updatedNetrcContent
func (l *login) updatedNetrcContent(
e *env,
content io.Reader,
credentials *credentials,
) ([]byte, error) {
tokens, err := netrc.Parse(content)
if err != nil {
return nil, stackerr.Wrap(err)
}
server, err := getHostFromURL(e.Server)
if err != nil {
return nil, err
}
machine := tokens.FindMachine(server)
if machine == nil {
machine = tokens.NewMachine(server, "default", credentials.token, "")
} else {
machine.UpdatePassword(credentials.token)
}
updatedContent, err := tokens.MarshalText()
if err != nil {
return nil, stackerr.Wrap(err)
}
return updatedContent, nil
}
示例3: round
func (l *logsCmd) round(e *env, c *context, startTime *parseTime) (*parseTime, error) {
v := make(url.Values)
v.Set("n", fmt.Sprint(l.num))
v.Set("level", l.level)
if startTime != nil {
b, err := json.Marshal(startTime)
if err != nil {
return nil, stackerr.Wrap(err)
}
v.Set("startTime", string(b))
}
u := &url.URL{
Path: "scriptlog",
RawQuery: v.Encode(),
}
var rows []logResponse
if _, err := e.ParseAPIClient.Get(u, &rows); err != nil {
return nil, stackerr.Wrap(err)
}
// logs come back in reverse
for i := len(rows) - 1; i >= 0; i-- {
fmt.Fprintln(e.Out, rows[i].Message)
}
if len(rows) > 0 {
return &rows[0].Timestamp, nil
}
return startTime, nil
}
示例4: functionHooksCreate
func (h *functionHooksCmd) functionHooksCreate(e *parsecli.Env, ctx *parsecli.Context) error {
params, err := readFunctionParams(e, h.Function)
if err != nil {
return err
}
var res functionHook
functionsURL, err := url.Parse(defaultFunctionsURL)
if err != nil {
return stackerr.Wrap(err)
}
_, err = e.ParseAPIClient.Post(functionsURL, params, &res)
if err != nil {
return stackerr.Wrap(err)
}
if res.Warning != "" {
fmt.Fprintf(e.Err, "WARNING: %s\n", res.Warning)
}
fmt.Fprintf(e.Out,
"Successfully created a webhook function %q pointing to %q\n",
res.FunctionName,
res.URL,
)
return nil
}
示例5: writeProjectConfig
func writeProjectConfig(p *projectConfig, path string) error {
b, err := json.MarshalIndent(p, "", " ")
if err != nil {
return stackerr.Wrap(err)
}
return stackerr.Wrap(ioutil.WriteFile(path, b, 0600))
}
示例6: create
func (s *UserService) create(req *restful.Request, resp *restful.Response) {
// TODO (m0sth8): Check permissions
raw := &user.User{}
if err := req.ReadEntity(raw); err != nil {
logrus.Error(stackerr.Wrap(err))
resp.WriteServiceError(http.StatusBadRequest, services.WrongEntityErr)
return
}
mgr := s.Manager()
defer mgr.Close()
obj, err := mgr.Users.Create(raw)
if err != nil {
if mgr.IsDup(err) {
resp.WriteServiceError(
http.StatusConflict,
services.NewError(services.CodeDuplicate, "user with this email is existed"))
return
}
logrus.Error(stackerr.Wrap(err))
resp.WriteServiceError(http.StatusInternalServerError, services.DbErr)
return
}
resp.WriteHeader(http.StatusCreated)
resp.WriteEntity(obj)
}
示例7: functionHooksUpdate
func (h *functionHooksCmd) functionHooksUpdate(e *parsecli.Env, ctx *parsecli.Context) error {
params, err := readFunctionParams(e, h.Function)
if err != nil {
return err
}
var res functionHook
functionsURL, err := url.Parse(path.Join(defaultFunctionsURL, params.FunctionName))
if err != nil {
return stackerr.Wrap(err)
}
_, err = e.ParseAPIClient.Put(functionsURL, &functionHook{URL: params.URL}, &res)
if err != nil {
return stackerr.Wrap(err)
}
if res.Warning != "" {
fmt.Fprintf(e.Err, "WARNING: %s\n", res.Warning)
}
fmt.Fprintf(e.Out,
"Successfully update the webhook function %q to point to %q\n",
res.FunctionName,
res.URL,
)
return nil
}
示例8: triggerHooksUpdate
func (h *triggerHooksCmd) triggerHooksUpdate(e *env, ctx *context) error {
params, err := readTriggerParams(e, h.Trigger)
if err != nil {
return err
}
var res triggerHook
triggersURL, err := url.Parse(path.Join(defaultTriggersURL, params.ClassName, params.TriggerName))
if err != nil {
return stackerr.Wrap(err)
}
_, err = e.ParseAPIClient.Put(triggersURL, &triggerHook{URL: params.URL}, &res)
if err != nil {
return stackerr.Wrap(err)
}
if res.Warning != "" {
fmt.Fprintf(e.Err, "WARNING: %s\n", res.Warning)
}
fmt.Fprintf(e.Out,
"Successfully update the %q trigger for class %q to point to %q\n",
res.TriggerName,
res.ClassName,
res.URL,
)
return nil
}
示例9: triggerHooksDelete
func (h *triggerHooksCmd) triggerHooksDelete(e *env, ctx *context) error {
params, err := readTriggerName(e, h.Trigger)
if err != nil {
return err
}
triggersURL, err := url.Parse(path.Join(defaultTriggersURL, params.ClassName, params.TriggerName))
if err != nil {
return stackerr.Wrap(err)
}
confirmMessage := fmt.Sprintf("Are you sure you want to delete %q webhook trigger for class: %q (y/n): ",
params.TriggerName,
params.ClassName,
)
var res triggerHook
if !h.interactive || getConfirmation(confirmMessage, e) {
_, err = e.ParseAPIClient.Put(triggersURL, map[string]interface{}{"__op": "Delete"}, &res)
if err != nil {
return stackerr.Wrap(err)
}
fmt.Fprintf(e.Out, "Successfully deleted %q webhook trigger for class %q\n",
params.TriggerName,
params.ClassName,
)
if res.TriggerName != "" && res.ClassName != "" {
fmt.Fprintf(e.Out, "%q trigger defined in cloudcode for class %q will be used henceforth\n",
res.TriggerName,
res.ClassName,
)
}
}
return nil
}
示例10: BestEffortDockerClient
// BestEfforDockerClient creates a docker client from one of:
//
// 1. Environment variables as defined in
// https://docs.docker.com/reference/commandline/cli/. Specifically
// DOCKER_HOST, DOCKER_TLS_VERIFY & DOCKER_CERT_PATH.
//
// 2. bootdocker, if darwin.
//
// 3. /run/docker.sock, if it exists.
//
// 4. /var/run/docker.sock, if it exists.
func BestEffortDockerClient() (*dockerclient.DockerClient, error) {
host := os.Getenv("DOCKER_HOST")
if host == "" {
if runtime.GOOS == "darwin" {
return Boot2DockerClient()
}
socketLocations := []string{"/run/docker.sock", "/var/run/docker.sock"}
for _, l := range socketLocations {
if _, err := os.Stat(l); err == nil {
c, err := dockerclient.NewDockerClient(fmt.Sprintf("unix://%s", l), nil)
if err != nil {
return nil, stackerr.Wrap(err)
}
return c, nil
}
}
return nil, stackerr.New("docker not configured")
}
if os.Getenv("DOCKER_TLS_VERIFY") != "" {
return DockerWithTLS(host, os.Getenv("DOCKER_CERT_PATH"))
}
c, err := dockerclient.NewDockerClient(host, nil)
if err != nil {
return nil, stackerr.Wrap(err)
}
return c, nil
}
示例11: DockerWithTLS
// DockerWithTLS returns a DockerClient with the certs in the specified
// directory. The names of the certs are the standard names of "cert.pem",
// "key.pem" and "ca.pem".
func DockerWithTLS(url, certPath string) (*dockerclient.DockerClient, error) {
var tlsConfig *tls.Config
clientCert, err := tls.LoadX509KeyPair(
filepath.Join(certPath, "cert.pem"),
filepath.Join(certPath, "key.pem"),
)
if err != nil {
return nil, stackerr.Wrap(err)
}
rootCAs := x509.NewCertPool()
caCert, err := ioutil.ReadFile(filepath.Join(certPath, "ca.pem"))
if err != nil {
return nil, stackerr.Wrap(err)
}
rootCAs.AppendCertsFromPEM(caCert)
tlsConfig = &tls.Config{
Certificates: []tls.Certificate{clientCert},
RootCAs: rootCAs,
}
client, err := dockerclient.NewDockerClient(url, tlsConfig)
if err != nil {
return nil, stackerr.Wrap(err)
}
return client, nil
}
示例12: update
// disabled
func (s *ScanService) update(req *restful.Request, resp *restful.Response, pl *scan.Scan) {
// TODO (m0sth8): Check permissions
// TODO (m0sth8): Forbid changes in scan after finished status
raw := &scan.Scan{}
if err := req.ReadEntity(raw); err != nil {
logrus.Error(stackerr.Wrap(err))
resp.WriteServiceError(http.StatusBadRequest, services.WrongEntityErr)
return
}
mgr := s.Manager()
defer mgr.Close()
raw.Id = pl.Id
if err := mgr.Scans.Update(raw); err != nil {
if mgr.IsNotFound(err) {
resp.WriteErrorString(http.StatusNotFound, "Not found")
return
}
if mgr.IsDup(err) {
resp.WriteServiceError(
http.StatusConflict,
services.NewError(services.CodeDuplicate, "scan with this name and version is existed"))
return
}
logrus.Error(stackerr.Wrap(err))
resp.WriteServiceError(http.StatusInternalServerError, services.DbErr)
return
}
resp.WriteHeader(http.StatusOK)
resp.WriteEntity(raw)
}
示例13: Create
// create file with data
func (m *FileManager) Create(r io.Reader, metaInfo *file.Meta) (*file.Meta, error) {
f, err := m.grid.Create("")
// according to gridfs code, the error here is impossible
if err != nil {
return nil, stackerr.Wrap(err)
}
size, err := io.Copy(f, r)
if err != nil {
return nil, stackerr.Wrap(err)
}
meta := &file.Meta{
Id: file.UniqueFileId(),
Size: int(size),
ContentType: metaInfo.ContentType,
Name: metaInfo.Name,
}
f.SetId(meta.Id)
f.SetMeta(meta)
if meta.ContentType != "" {
f.SetContentType(meta.ContentType)
}
if err = f.Close(); err != nil {
return nil, stackerr.Wrap(err)
}
return meta, nil
}
示例14: deleteHook
func (c *configureCmd) deleteHook(
e *env,
hooksOps []*hookOperation,
fields ...string,
) (bool, []*hookOperation, error) {
restOp := strings.ToUpper(fields[0])
if restOp != "DELETE" {
return false, nil, stackerr.Wrap(errInvalidFormat)
}
switch len(fields) {
case 2:
hooksOps = append(hooksOps, &hookOperation{
method: "DELETE",
function: &functionHook{FunctionName: fields[1]},
})
return true, hooksOps, nil
case 3:
if err := c.checkTriggerName(fields[2]); err != nil {
return false, nil, err
}
hooksOps = append(hooksOps, &hookOperation{
method: "DELETE",
trigger: &triggerHook{ClassName: fields[1], TriggerName: fields[2]},
})
return true, hooksOps, nil
}
return false, nil, stackerr.Wrap(errInvalidFormat)
}
示例15: send
func send(s mangos.Socket, obj interface{}) error {
data, err := json.Marshal(obj)
if err != nil {
return stackerr.Wrap(err)
}
return stackerr.Wrap(s.Send(data))
}