• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang timex.Now函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/remind101/pkg/timex.Now函数的典型用法代码示例。如果您正苦于以下问题:Golang Now函数的具体用法?Golang Now怎么用?Golang Now使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Now函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: newServiceProcess

func newServiceProcess(release *Release, p *Process) *service.Process {
	var procExp service.Exposure
	ports := newServicePorts(int64(p.Port))

	env := environment(release.Config.Vars)
	env["EMPIRE_APPNAME"] = release.App.Name
	env["EMPIRE_PROCESS"] = string(p.Type)
	env["EMPIRE_RELEASE"] = fmt.Sprintf("v%d", release.Version)
	env["EMPIRE_CREATED_AT"] = timex.Now().Format(time.RFC3339)
	env["SOURCE"] = fmt.Sprintf("%s.v%d.%s", release.App.Name, release.Version, p.Type)

	if len(ports) > 0 {
		env["PORT"] = fmt.Sprintf("%d", *ports[0].Container)

		// If we have exposed ports, set process exposure to apps exposure
		procExp = serviceExposure(release.App.Exposure)
	}

	cert := serviceSSLCertName(release.App.Certificates)

	return &service.Process{
		Type:        string(p.Type),
		Env:         env,
		Command:     string(p.Command),
		Image:       release.Slug.Image.String(),
		Instances:   uint(p.Quantity),
		MemoryLimit: uint(p.Constraints.Memory),
		CPUShares:   uint(p.Constraints.CPUShare),
		Ports:       ports,
		Exposure:    procExp,
		SSLCert:     cert,
	}
}
开发者ID:yourchanges,项目名称:empire,代码行数:33,代码来源:releases.go


示例2: WithRequest

// WithRequest inserts an http.Request into the context.
func WithRequest(ctx context.Context, r *http.Request) context.Context {
	return &requestContext{
		Context:   ctx,
		startedAt: timex.Now(),
		r:         r,
	}
}
开发者ID:carriercomm,项目名称:empire,代码行数:8,代码来源:httpx.go


示例3: BeforeCreate

func (a *App) BeforeCreate() error {
	t := timex.Now()
	a.CreatedAt = &t

	if a.Exposure == "" {
		a.Exposure = exposePrivate
	}

	return a.IsValid()
}
开发者ID:brianz,项目名称:empire,代码行数:10,代码来源:apps.go


示例4: ServeHTTPContext

func (h *PostProcess) ServeHTTPContext(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
	var form PostProcessForm

	a, err := findApp(ctx, h)
	if err != nil {
		return err
	}

	if err := Decode(r, &form); err != nil {
		return err
	}

	opts := empire.RunOpts{
		User:    UserFromContext(ctx),
		App:     a,
		Command: form.Command,
		Env:     form.Env,
	}

	if form.Attach {
		inStream, outStream, err := hijackServer(w)
		if err != nil {
			return err
		}
		defer closeStreams(inStream, outStream)

		fmt.Fprintf(outStream, "HTTP/1.1 200 OK\r\nContent-Type: application/vnd.empire.raw-stream\r\n\r\n")

		// Prevent the ELB idle connection timeout to close the connection.
		defer close(streamhttp.Heartbeat(outStream, 10*time.Second))

		opts.Input = inStream
		opts.Output = outStream

		if err := h.Run(ctx, opts); err != nil {
			fmt.Fprintf(outStream, "%v", err)
			return nil
		}
	} else {
		if err := h.Run(ctx, opts); err != nil {
			return err
		}

		dyno := &heroku.Dyno{
			Name:      "run",
			Command:   form.Command,
			CreatedAt: timex.Now(),
		}

		w.WriteHeader(201)
		return Encode(w, dyno)
	}

	return nil
}
开发者ID:frewsxcv,项目名称:empire,代码行数:55,代码来源:processes.go


示例5: Relay

func (f *fakeRelayer) Relay(ctx context.Context, c *postContainersForm) (*ContainerRelay, error) {
	return &ContainerRelay{
		Name:      "run.123",
		AttachURL: "fake://example.com:5000/abc",
		Command:   c.Command,
		State:     "starting",
		Type:      "run",
		Size:      "1X",
		CreatedAt: timex.Now(),
	}, nil
}
开发者ID:yourchanges,项目名称:empire,代码行数:11,代码来源:runner.go


示例6: Instances

func (m *FakeScheduler) Instances(ctx context.Context, appID string) ([]*Instance, error) {
	var instances []*Instance
	if a, ok := m.apps[appID]; ok {
		for _, p := range a.Processes {
			for i := uint(1); i <= p.Instances; i++ {
				instances = append(instances, &Instance{
					ID:        fmt.Sprintf("%d", i),
					State:     "running",
					Process:   p,
					UpdatedAt: timex.Now(),
				})
			}
		}
	}
	return instances, nil
}
开发者ID:frewsxcv,项目名称:empire,代码行数:16,代码来源:fake.go


示例7: newServiceProcess

func newServiceProcess(release *Release, p *Process) *scheduler.Process {
	var procExp scheduler.Exposure
	ports := newServicePorts(int64(p.Port))

	env := environment(release.Config.Vars)
	env["EMPIRE_APPID"] = release.App.ID
	env["EMPIRE_APPNAME"] = release.App.Name
	env["EMPIRE_PROCESS"] = string(p.Type)
	env["EMPIRE_RELEASE"] = fmt.Sprintf("v%d", release.Version)
	env["EMPIRE_CREATED_AT"] = timex.Now().Format(time.RFC3339)
	env["SOURCE"] = fmt.Sprintf("%s.%s.v%d", release.App.Name, p.Type, release.Version)

	labels := map[string]string{
		"empire.app.id":      release.App.ID,
		"empire.app.name":    release.App.Name,
		"empire.app.process": string(p.Type),
		"empire.app.release": fmt.Sprintf("v%d", release.Version),
	}

	if len(ports) > 0 {
		env["PORT"] = fmt.Sprintf("%d", *ports[0].Container)

		// gliderlabs registrator
		labels[fmt.Sprintf("SERVICE_%d_NAME", *ports[0].Container)] = release.App.Name

		// If we have exposed ports, set process exposure to apps exposure
		procExp = serviceExposure(release.App.Exposure)
	}

	return &scheduler.Process{
		Type:        string(p.Type),
		Env:         env,
		Labels:      labels,
		Command:     string(p.Command),
		Image:       release.Slug.Image,
		Instances:   uint(p.Quantity),
		MemoryLimit: uint(p.Constraints.Memory),
		CPUShares:   uint(p.Constraints.CPUShare),
		Ports:       ports,
		Exposure:    procExp,
		SSLCert:     release.App.Cert,
	}
}
开发者ID:jjbohn,项目名称:empire,代码行数:43,代码来源:releases.go


示例8: Instances

// Instances returns all instances that are currently running, pending or
// draining.
func (m *Scheduler) Instances(ctx context.Context, appID string) ([]*scheduler.Instance, error) {
	var instances []*scheduler.Instance

	tasks, err := m.describeAppTasks(ctx, appID)
	if err != nil {
		return instances, err
	}

	for _, t := range tasks {
		resp, err := m.ecs.DescribeTaskDefinition(ctx, &ecs.DescribeTaskDefinitionInput{
			TaskDefinition: t.TaskDefinitionArn,
		})
		if err != nil {
			return instances, err
		}

		id, err := arn.ResourceID(*t.TaskArn)
		if err != nil {
			return instances, err
		}

		p, err := taskDefinitionToProcess(resp.TaskDefinition)
		if err != nil {
			return instances, err
		}

		instances = append(instances, &scheduler.Instance{
			Process:   p,
			State:     safeString(t.LastStatus),
			ID:        id,
			UpdatedAt: timex.Now(),
		})
	}

	return instances, nil
}
开发者ID:4eek,项目名称:empire,代码行数:38,代码来源:ecs.go


示例9: BeforeCreate

func (d *Domain) BeforeCreate() error {
	t := timex.Now()
	d.CreatedAt = &t
	return nil
}
开发者ID:brianz,项目名称:empire,代码行数:5,代码来源:domains.go


示例10: BeforeCreate

// Set created_at before inserting.
func (r *Release) BeforeCreate() error {
	t := timex.Now()
	r.CreatedAt = &t
	return nil
}
开发者ID:yourchanges,项目名称:empire,代码行数:6,代码来源:releases.go


示例11: BeforeUpdate

// PreUpdate implements a pre insert hook for the db interface
func (c *Certificate) BeforeUpdate() error {
	t := timex.Now()
	c.UpdatedAt = &t
	return nil
}
开发者ID:yourchanges,项目名称:empire,代码行数:6,代码来源:ssl.go


示例12: ServeHTTPContext

func (h *PostProcess) ServeHTTPContext(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
	var form PostProcessForm

	a, err := findApp(ctx, h)
	if err != nil {
		return err
	}

	m, err := findMessage(r)
	if err != nil {
		return err
	}

	if err := Decode(r, &form); err != nil {
		return err
	}

	command, err := empire.ParseCommand(form.Command)
	if err != nil {
		return err
	}

	opts := empire.RunOpts{
		User:        UserFromContext(ctx),
		App:         a,
		Command:     command,
		Env:         form.Env,
		Constraints: form.Size,
		Message:     m,
	}

	if form.Attach {
		header := http.Header{}
		header.Set("Content-Type", "application/vnd.empire.raw-stream")
		stream := &hijack.HijackReadWriter{
			Response: w,
			Header:   header,
		}
		defer stream.Close()
		// Prevent the ELB idle connection timeout to close the connection.
		defer close(streamhttp.Heartbeat(stream, 10*time.Second))

		opts.Input = stream
		opts.Output = stream

		if err := h.Run(ctx, opts); err != nil {
			if stream.Hijacked {
				fmt.Fprintf(stream, "%v\r", err)
				return nil
			}
			return err
		}
	} else {
		if err := h.Run(ctx, opts); err != nil {
			return err
		}

		dyno := &heroku.Dyno{
			Name:      "run",
			Command:   form.Command,
			CreatedAt: timex.Now(),
		}

		w.WriteHeader(201)
		return Encode(w, dyno)
	}

	return nil
}
开发者ID:brianz,项目名称:empire,代码行数:69,代码来源:processes.go



注:本文中的github.com/remind101/pkg/timex.Now函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang trace.Trace函数代码示例发布时间:2022-05-28
下一篇:
Golang image.Image类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap