当前位置: 首页>>代码示例>>Golang>>正文


Golang Task.InstanceSpecificPrivateDomainName方法代码示例

本文整理汇总了Golang中github.com/pulcy/j2/jobs.Task.InstanceSpecificPrivateDomainName方法的典型用法代码示例。如果您正苦于以下问题:Golang Task.InstanceSpecificPrivateDomainName方法的具体用法?Golang Task.InstanceSpecificPrivateDomainName怎么用?Golang Task.InstanceSpecificPrivateDomainName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/pulcy/j2/jobs.Task的用法示例。


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

示例1: addFrontEndRegistration

// addFrontEndRegistration adds registration code for frontends to the given units
func addFrontEndRegistration(t *jobs.Task, main *sdunits.Unit, ctx generatorContext) error {
	if len(t.PublicFrontEnds) == 0 && len(t.PrivateFrontEnds) == 0 {
		return nil
	}
	serviceName := t.ServiceName()
	targetServiceName := serviceName
	if t.Type == "proxy" {
		targetServiceName = t.Target.EtcdServiceName()
	}
	httpKey := fmt.Sprintf("/pulcy/frontend/%s-%d", serviceName, ctx.ScalingGroup)
	httpRecord := api.FrontendRecord{
		Service:         targetServiceName,
		HttpCheckPath:   t.HttpCheckPath,
		HttpCheckMethod: t.HttpCheckMethod,
		Sticky:          t.Sticky,
		Backup:          t.Backup,
		Mode:            "", // Defaults to http
	}
	tcpKey := fmt.Sprintf("/pulcy/frontend/%s-%d-tcp", serviceName, ctx.ScalingGroup)
	tcpRecord := api.FrontendRecord{
		Service:         targetServiceName,
		HttpCheckPath:   t.HttpCheckPath,
		HttpCheckMethod: t.HttpCheckMethod,
		Sticky:          t.Sticky,
		Backup:          t.Backup,
		Mode:            "tcp",
	}
	instanceHttpKey := fmt.Sprintf("/pulcy/frontend/%s-%d-inst", serviceName, ctx.ScalingGroup)
	instanceHttpRecord := api.FrontendRecord{
		Service:       fmt.Sprintf("%s-%d", targetServiceName, ctx.ScalingGroup),
		HttpCheckPath: t.HttpCheckPath,
		Sticky:        t.Sticky,
		Backup:        t.Backup,
	}
	instanceTcpKey := fmt.Sprintf("/pulcy/frontend/%s-%d-inst-tcp", serviceName, ctx.ScalingGroup)
	instanceTcpRecord := api.FrontendRecord{
		Service:       fmt.Sprintf("%s-%d", targetServiceName, ctx.ScalingGroup),
		HttpCheckPath: t.HttpCheckPath,
		Sticky:        t.Sticky,
		Backup:        t.Backup,
		Mode:          "tcp",
	}
	var rwRules []api.RewriteRule
	if t.Type == "proxy" && t.Rewrite != nil {
		rwRules = append(rwRules, api.RewriteRule{
			PathPrefix:       t.Rewrite.PathPrefix,
			RemovePathPrefix: t.Rewrite.RemovePathPrefix,
			Domain:           t.Rewrite.Domain,
		})
	}

	for _, fr := range t.PublicFrontEnds {
		record := &httpRecord
		if fr.Mode == "tcp" {
			record = &tcpRecord
		}
		selRecord := api.FrontendSelectorRecord{
			Weight:       fr.Weight,
			Domain:       fr.Domain,
			PathPrefix:   fr.PathPrefix,
			SslCert:      fr.SslCert,
			ServicePort:  fr.Port,
			FrontendPort: fr.HostPort,
			RewriteRules: rwRules,
		}
		if err := addUsers(t, &selRecord, fr.Users); err != nil {
			return maskAny(err)
		}
		record.Selectors = append(record.Selectors, selRecord)
	}
	for _, fr := range t.PrivateFrontEnds {
		record := &httpRecord
		instanceRecord := &instanceHttpRecord
		if fr.Mode == "tcp" {
			record = &tcpRecord
			instanceRecord = &instanceTcpRecord
		}
		selRecord := api.FrontendSelectorRecord{
			Domain:       t.PrivateDomainName(),
			ServicePort:  fr.Port,
			FrontendPort: fr.HostPort,
			Private:      true,
			RewriteRules: rwRules,
		}
		if err := addUsers(t, &selRecord, fr.Users); err != nil {
			return maskAny(err)
		}
		record.Selectors = append(record.Selectors, selRecord)

		if fr.RegisterInstance {
			instanceSelRecord := selRecord
			instanceSelRecord.Domain = t.InstanceSpecificPrivateDomainName(ctx.ScalingGroup)
			instanceRecord.Selectors = append(instanceRecord.Selectors, instanceSelRecord)
		}
	}

	if len(instanceHttpRecord.Selectors) > 0 {
		if err := addFrontEndRegistrationRecord(t, main, instanceHttpKey, instanceHttpRecord, "FrontEndRegistration-i"); err != nil {
			return maskAny(err)
//.........这里部分代码省略.........
开发者ID:pulcy,项目名称:j2,代码行数:101,代码来源:frontend_registration.go


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