當前位置: 首頁>>代碼示例>>Golang>>正文


Golang timex.Now函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。