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


Golang typewriter.Type类代码示例

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


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

示例1: Write

func (g *ModelGenerator) Write(writer io.Writer, t typewriter.Type) error {
	tag, found := t.FindTag(g)

	if !found {
		return nil
	}

	// Fetch core template
	coreTemplates := templates.Where(func(t *typewriter.Template) bool {
		if t != nil && t.Name == "core" {
			return true
		}

		return false
	})
	if len(coreTemplates) == 0 {
		return errors.New("Unable to find 'core' template")
	}
	coreTemplate, err := coreTemplates[0].Parse()
	if err != nil {
		return errors.New("Unable to parse 'core' template")
	}

	// Fetch relation template
	relationTemplates := templates.Where(func(t *typewriter.Template) bool {
		if t != nil && t.Name == "relation" {
			return true
		}

		return false
	})
	if len(relationTemplates) == 0 {
		return errors.New("Unable to find 'relation' template")
	}
	relationTemplate, err := relationTemplates[0].Parse()
	if err != nil {
		return errors.New("Unable to parse 'relation' template")
	}

	cValues := coreValues{ModelClassName: t.Name}
	if err := coreTemplate.Execute(writer, cValues); err != nil {
		return err
	}

	for _, relation := range tag.Values {
		templateValues := relationValues{}

		templateValues.ModelClassName = t.Name
		templateValues.RelationIdentifierName = fmt.Sprintf("%vIdentifier", strings.Title(relation.Name))
		templateValues.RelationName = relation.Name
		templateValues.RelationClassName = strings.Title(relation.Name)

		if err := relationTemplate.Execute(writer, templateValues); err != nil {
			return err
		}
	}

	return nil
}
开发者ID:sparkymat,项目名称:clay,代码行数:59,代码来源:model_generator.go

示例2: Write

func (sw *SequenceGeneratorWriter) Write(w io.Writer, t typewriter.Type) error {
	tag, found := t.FindTag(sw)
	if !found {
		return nil
	}

	if _, err := w.Write([]byte(license)); err != nil {
		return err
	}

	generatorName := t.Name
	for _, v := range tag.Values {
		switch v.Name {
		case "Iterator":
			if len(v.TypeParameters) == 0 {
				return errors.New("No type parameters for Iterate tag")
			}
			typeParameters := v.TypeParameters
			v.TypeParameters = make([]typewriter.Type, 0)

			tmpl, err := templates.ByTagValue(t, v)
			if err != nil {
				return err
			}
			for _, typ := range typeParameters {
				typeName := typ.Pointer.String() + typ.Name
				if typeName == "*bigInt" {
					typeName = "*big.Int"
				} else if typeName == "*bigRat" {
					typeName = "*bigRat"
				}
				typeTitle := typeTitle[typeName]
				if typeTitle == "" {
					return fmt.Errorf("Unexpected type: %s", typeName)
				}
				tmpl.Execute(w, generatorModel{generatorName, typeName, typeTitle})
			}
			return nil
		default:
			return fmt.Errorf("Unrecognized tag: %s", v.Name)
		}
	}

	return nil
}
开发者ID:fernandokm,项目名称:sequences,代码行数:45,代码来源:sequenceGeneratorWriter.go

示例3: Write

func (tw *writer) Write(w io.Writer, t typewriter.Type) error {
	tag, found := t.FindTag(tw)

	if !found {
		return nil
	}

	header := "// DO NOT MODIFY. Auto-generated code."
	if _, err := w.Write([]byte(header)); err != nil {
		return err
	}

	tmpl, err := templates.ByTag(t, tag)
	if err != nil {
		return err
	}

	if err := tmpl.Execute(w, t); err != nil {
		return err
	}
	return nil
}
开发者ID:svett,项目名称:gen,代码行数:22,代码来源:writer.go

示例4: Write

func (sw *SymTableWriter) Write(w io.Writer, t typewriter.Type) error {
	tag, found := t.FindTag(sw)

	if !found {
		// nothing to be done
		return nil
	}

	log.Printf("Found tag %+v\n", tag)

	license := `// SymTableWriter is a modification of https://github.com/deckarep/golang-set
// The MIT License (MIT)
// Copyright (c) 2015 Yo-An Lin ([email protected])
`
	if _, err := w.Write([]byte(license)); err != nil {
		return err
	}

	log.Printf("Finding template by tag %+v\n", tag)
	tmpl, err := templates.ByTag(t, tag)
	if err != nil {
		return err
	}

	m := model{
		Type:          t,
		Name:          t.Name,
		TypeParameter: tag.Values[0].TypeParameters[0],
		Tag:           tag,
	}

	log.Println("Rendering templates")
	if err := tmpl.Execute(w, m); err != nil {
		return err
	}

	log.Println("Done!")
	return nil
}
开发者ID:se77en,项目名称:c6,代码行数:39,代码来源:writer.go

示例5: Write

func (cw *ContainerWriter) Write(w io.Writer, typ typewriter.Type) error {
	containerTag, found := typ.FindTag(cw)

	if !found {
		return nil
	}

	if _, err := w.Write([]byte(license)); err != nil {
		return err
	}

	for _, tagValue := range containerTag.Values {
		if tmpl, err := templates.ByTagValue(typ, tagValue); err != nil {
			return err
		} else if m, err := typeAndTagValueToModel(typ, tagValue); err != nil {
			return err
		} else if err := tmpl.Execute(w, *m); err != nil {
			return err
		}
	}

	return nil
}
开发者ID:nickmab,项目名称:gen,代码行数:23,代码来源:containerwriter.go

示例6: Write

func (fw *Writer) Write(w io.Writer, typ typewriter.Type) error {
	tag, found := typ.FindTag(fw)

	if !found {
		return nil
	}

	tmpl, err := templates.ByTag(typ, tag)
	if err != nil {
		return err
	}

	m := model{
		Type:      typ,
		SliceName: SliceName(typ),
	}

	if err := tmpl.Execute(w, m); err != nil {
		return err
	}

	return nil
}
开发者ID:publicgoodsw,项目名称:flags,代码行数:23,代码来源:writer.go

示例7: Write

func (sw *SliceWriter) Write(w io.Writer, typ typewriter.Type) error {
	tag, found := typ.FindTag(sw)

	if !found {
		return nil
	}

	if includeSortImplementation(tag.Values) {
		s := `// Sort implementation is a modification of http://golang.org/pkg/sort/#Sort
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found at http://golang.org/LICENSE.

`
		w.Write([]byte(s))
	}

	// start with the slice template
	tmpl, err := templates.ByTag(typ, tag)

	if err != nil {
		return err
	}

	m := model{
		Type:      typ,
		SliceName: SliceName(typ),
	}

	if err := tmpl.Execute(w, m); err != nil {
		return err
	}

	for _, v := range tag.Values {
		var tp typewriter.Type

		if len(v.TypeParameters) > 0 {
			tp = v.TypeParameters[0]
		}

		m := model{
			Type:          typ,
			SliceName:     SliceName(typ),
			TypeParameter: tp,
			TagValue:      v,
		}

		tmpl, err := templates.ByTagValue(typ, v)

		if err != nil {
			return err
		}

		if err := tmpl.Execute(w, m); err != nil {
			return err
		}
	}

	if includeSortInterface(tag.Values) {
		tmpl, err := sortInterface.Parse()

		if err != nil {
			return err
		}

		if err := tmpl.Execute(w, m); err != nil {
			return err
		}
	}

	if includeSortImplementation(tag.Values) {
		tmpl, err := sortImplementation.Parse()

		if err != nil {
			return err
		}

		if err := tmpl.Execute(w, m); err != nil {
			return err
		}
	}

	return nil
}
开发者ID:clamoriniere1A,项目名称:sliceP,代码行数:84,代码来源:slicewriter.go


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