示例#1
0
func (cfg *ServerConfig) Heim(ctx scope.Context) (*proto.Heim, error) {
	pageTemplater, err := LoadPageTemplates(filepath.Join(cfg.StaticPath, "pages"))
	if err != nil {
		return nil, fmt.Errorf("page templates: %s", err)
	}

	// Load and verify page templates.
	c, err := cfg.Cluster.EtcdCluster(ctx)
	if err != nil {
		return nil, err
	}

	kms, err := cfg.KMS.Get()
	if err != nil {
		return nil, err
	}

	emailTemplater, emailDeliverer, err := cfg.Email.Get(cfg)
	if err != nil {
		return nil, err
	}

	heim := &proto.Heim{
		Context:        ctx,
		Cluster:        c,
		PeerDesc:       cfg.Cluster.DescribeSelf(),
		KMS:            kms,
		EmailDeliverer: emailDeliverer,
		EmailTemplater: emailTemplater,
		GeoIP:          cfg.GeoIP.Api(),
		PageTemplater:  pageTemplater,
		SiteName:       cfg.SiteName,
		StaticPath:     cfg.StaticPath,
	}

	backend, err := cfg.GetBackend(heim)
	if err != nil {
		return nil, err
	}

	emojiPath := filepath.Join(cfg.StaticPath, "emoji.json")
	if err = proto.LoadEmoji(emojiPath); err != nil {
		fmt.Printf("error loading %s: %s\n", emojiPath, err)
	}

	heim.Backend = backend
	return heim, nil
}
示例#2
0
func (cfg *ServerConfig) Heim(ctx scope.Context) (*proto.Heim, error) {
	c, err := cfg.Cluster.EtcdCluster(ctx)
	if err != nil {
		return nil, err
	}

	kms, err := cfg.KMS.Get()
	if err != nil {
		return nil, err
	}

	emailTemplater, emailDeliverer, err := cfg.Email.Get(cfg)
	if err != nil {
		return nil, err
	}

	heim := &proto.Heim{
		Context:        ctx,
		Cluster:        c,
		PeerDesc:       cfg.Cluster.DescribeSelf(),
		KMS:            kms,
		EmailTemplater: emailTemplater,
		EmailDeliverer: emailDeliverer,
		StaticPath:     cfg.StaticPath,
	}

	backend, err := cfg.GetBackend(heim)
	if err != nil {
		return nil, err
	}

	emojiPath := filepath.Join(cfg.StaticPath, "emoji.json")
	if err = proto.LoadEmoji(emojiPath); err != nil {
		fmt.Printf("error loading %s: %s\n", emojiPath, err)
	}

	heim.Backend = backend
	return heim, nil
}