Skip to content

Commit 6969820

Browse files
committed
godoc cleanups
1 parent e78babb commit 6969820

11 files changed

+75
-56
lines changed

definitions.go

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import (
55
"github.com/goadesign/goa/dslengine"
66
)
77

8-
// RelationalStorageType is the type of database
8+
// RelationalStorageType is the type of database.
99
type RelationalStorageType string
1010

11-
// FieldType is the storage data type for a database field
11+
// FieldType is the storage data type for a database field.
1212
type FieldType string
1313

14-
// StorageGroupDefinition is the parent configuration structure for Gorma definitions
14+
// StorageGroupDefinition is the parent configuration structure for Gorma definitions.
1515
type StorageGroupDefinition struct {
1616
dslengine.Definition
1717
DefinitionDSL func()
@@ -20,7 +20,7 @@ type StorageGroupDefinition struct {
2020
RelationalStores map[string]*RelationalStoreDefinition
2121
}
2222

23-
// RelationalStoreDefinition is the parent configuration structure for Gorm relational model definitions
23+
// RelationalStoreDefinition is the parent configuration structure for Gorm relational model definitions.
2424
type RelationalStoreDefinition struct {
2525
dslengine.Definition
2626
DefinitionDSL func()
@@ -35,7 +35,7 @@ type RelationalStoreDefinition struct {
3535
}
3636

3737
// RelationalModelDefinition implements the storage of a domain model into a
38-
// table in a relational database
38+
// table in a relational database.
3939
type RelationalModelDefinition struct {
4040
dslengine.Definition
4141
*design.UserTypeDefinition
@@ -63,7 +63,7 @@ type RelationalModelDefinition struct {
6363
}
6464

6565
// BuildSource stores the BuildsFrom sources
66-
// for parsing
66+
// for parsing.
6767
type BuildSource struct {
6868
dslengine.Definition
6969
DefinitionDSL func()
@@ -72,15 +72,16 @@ type BuildSource struct {
7272
}
7373

7474
// MapDefinition represents field mapping to and from
75-
// Gorma models
75+
// Gorma models.
7676
type MapDefinition struct {
7777
RemoteType *design.UserTypeDefinition
7878
RemoteField string
7979
}
8080

8181
// MediaTypeAdapterDefinition represents the transformation of a
82-
// Goa media type into a Gorma Model
83-
// Unimplemented at this time
82+
// Goa media type into a Gorma Model.
83+
//
84+
// Unimplemented at this time.
8485
type MediaTypeAdapterDefinition struct {
8586
dslengine.Definition
8687
DefinitionDSL func()
@@ -91,8 +92,9 @@ type MediaTypeAdapterDefinition struct {
9192
}
9293

9394
// UserTypeAdapterDefinition represents the transformation of a Goa
94-
// user type into a Gorma Model
95-
// Unimplemented at this time
95+
// user type into a Gorma Model.
96+
//
97+
// Unimplemented at this time.
9698
type UserTypeAdapterDefinition struct {
9799
dslengine.Definition
98100
DefinitionDSL func()
@@ -103,9 +105,10 @@ type UserTypeAdapterDefinition struct {
103105
}
104106

105107
// PayloadAdapterDefinition represents the transformation of a Goa
106-
// Payload (which is really a UserTypeDefinition
107-
// into a Gorma model
108-
// Unimplemented at this time
108+
// Payload (which is really a UserTypeDefinition)
109+
// into a Gorma model.
110+
//
111+
// Unimplemented at this time.
109112
type PayloadAdapterDefinition struct {
110113
dslengine.Definition
111114
DefinitionDSL func()
@@ -116,7 +119,7 @@ type PayloadAdapterDefinition struct {
116119
}
117120

118121
// RelationalFieldDefinition represents
119-
// a field in a relational database
122+
// a field in a relational database.
120123
type RelationalFieldDefinition struct {
121124
dslengine.Definition
122125
DefinitionDSL func()
@@ -140,7 +143,7 @@ type RelationalFieldDefinition struct {
140143
}
141144

142145
// ManyToManyDefinition stores information about a ManyToMany
143-
// relationship between two domain objects
146+
// relationship between two domain objects.
144147
type ManyToManyDefinition struct {
145148
dslengine.Definition
146149
DefinitionDSL func()
@@ -151,17 +154,17 @@ type ManyToManyDefinition struct {
151154
}
152155

153156
// StoreIterator is a function that iterates over Relational Stores in a
154-
// StorageGroup
157+
// StorageGroup.
155158
type StoreIterator func(m *RelationalStoreDefinition) error
156159

157160
// ModelIterator is a function that iterates over Models in a
158-
// RelationalStore
161+
// RelationalStore.
159162
type ModelIterator func(m *RelationalModelDefinition) error
160163

161164
// FieldIterator is a function that iterates over Fields
162-
// in a RelationalModel
165+
// in a RelationalModel.
163166
type FieldIterator func(m *RelationalFieldDefinition) error
164167

165168
// BuildSourceIterator is a function that iterates over Fields
166-
// in a RelationalModel
169+
// in a RelationalModel.
167170
type BuildSourceIterator func(m *BuildSource) error

dsl/relationalfield.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,18 @@ import (
1313

1414
// Field is a DSL definition for a field in a Relational Model.
1515
// Parameter Options:
16-
// A field called "Title" with type String
17-
// Field("Title")
18-
// Explicitly specify the type
19-
// Field("Title", gorma.String)
20-
// "Title" field, as String with other DSL included
21-
// Field("Title", func(){... other field level dsl ...})
22-
// All options specified, name, type and dsl
23-
// Field("Title", gorma.String, func(){... other field level dsl ...})
16+
//
17+
// // A field called "Title" with default type `String`.
18+
// Field("Title")
19+
//
20+
// // Explicitly specify the type.
21+
// Field("Title", gorma.String)
22+
//
23+
// // "Title" field, as `String` with other DSL included.
24+
// Field("Title", func(){... other field level dsl ...})
25+
//
26+
// // All options specified: name, type and dsl.
27+
// Field("Title", gorma.String, func(){... other field level dsl ...})
2428
func Field(name string, args ...interface{}) {
2529
// We can't rely on this being run first, any of the top level DSL could run
2630
// in any order. The top level DSLs are API, Version, Resource, MediaType and Type.

dsl/relationalmodel.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
// to define the mapping between a Model and a Goa Type.
1818
// Models may contain multiple instances of the `Field` DSL to
1919
// add fields to the model.
20+
//
2021
// To control whether the ID field is auto-generated, use `NoAutomaticIDFields()`
2122
// Similarly, use NoAutomaticTimestamps() and NoAutomaticSoftDelete() to
2223
// prevent CreatedAt, UpdatedAt and DeletedAt fields from being created.
@@ -83,7 +84,8 @@ func Model(name string, dsl func()) {
8384
// RendersTo informs Gorma that this model will need to be
8485
// rendered to a Goa type. Conversion functions
8586
// will be generated to convert to/from the model.
86-
// Usage: RendersTo(MediaType)
87+
//
88+
// Usage: RendersTo(MediaType)
8789
func RendersTo(rt interface{}) {
8890
checkInit()
8991
if m, ok := relationalModelDefinition(false); ok {
@@ -98,7 +100,9 @@ func RendersTo(rt interface{}) {
98100
// BuildsFrom informs Gorma that this model will be populated
99101
// from a Goa UserType. Conversion functions
100102
// will be generated to convert from the payload to the model.
103+
//
101104
// Usage: BuildsFrom(YourType)
105+
//
102106
// Fields not in `YourType` that you want in your model must be
103107
// added explicitly with the `Field` DSL.
104108
func BuildsFrom(dsl func()) {
@@ -121,7 +125,7 @@ func BuildsFrom(dsl func()) {
121125
}
122126

123127
// Payload specifies the Resource and Action containing
124-
// a User Type (Payload)
128+
// a User Type (Payload).
125129
// Gorma will generate a conversion function for the Payload to
126130
// the Model.
127131
func Payload(r interface{}, act string) {
@@ -155,6 +159,7 @@ func Payload(r interface{}, act string) {
155159
// BelongsTo signifies a relationship between this model and a
156160
// Parent. The Parent has the child, and the Child belongs
157161
// to the Parent.
162+
//
158163
// Usage: BelongsTo("User")
159164
func BelongsTo(parent string) {
160165
if r, ok := relationalModelDefinition(false); ok {
@@ -182,6 +187,7 @@ func BelongsTo(parent string) {
182187
// to have a ThisModelID field as a Foreign Key to this model's
183188
// Primary Key. ThisModel will have a field named OtherModel of type
184189
// OtherModel.
190+
//
185191
// Usage: HasOne("Proposal")
186192
func HasOne(child string) {
187193
if r, ok := relationalModelDefinition(false); ok {
@@ -232,7 +238,9 @@ func HasOne(child string) {
232238
// of the child model. The Child model will have a ParentID field
233239
// appended to the field list. The Parent model definition will use
234240
// the first parameter as the field name in the struct definition.
241+
//
235242
// Usage: HasMany("Orders", "Order")
243+
//
236244
// Generated struct field definition: Children []Child
237245
func HasMany(name, child string) {
238246
if r, ok := relationalModelDefinition(false); ok {
@@ -279,9 +287,11 @@ func HasMany(name, child string) {
279287
// between this model and another model. For example, in retail an Order can
280288
// contain many products, and a product can belong to many orders. To express
281289
// this relationship use the following syntax:
282-
// Model("Order", func(){
283-
// ManyToMany("Product", "order_lines")
284-
// })
290+
//
291+
// Model("Order", func(){
292+
// ManyToMany("Product", "order_lines")
293+
// })
294+
//
285295
// This specifies that the Order and Product tables have a "junction" table
286296
// called `order_lines` that contains the order and product information.
287297
// The generated model will have a field called `Products` that will

init.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ const (
6161
BelongsTo FieldType = "belongsto"
6262
)
6363

64-
// Init creates the necessary data structures for parsing a DSL
64+
// Init creates the necessary data structures for parsing a DSL.
6565
// Should not be called directly, but instead is called
66-
// by many of the DSL functions to ensure that the design is initialized
66+
// by many of the DSL functions to ensure that the design is initialized.
6767
func Init() {
6868
sg := NewStorageGroupDefinition()
6969
dslengine.Roots = append(dslengine.Roots, sg)

manytomany.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,37 @@ import (
77
)
88

99
// LeftNamePlural returns the pluralized version of
10-
// the "owner" of the m2m relationship
10+
// the "owner" of the m2m relationship.
1111
func (m *ManyToManyDefinition) LeftNamePlural() string {
1212
return inflect.Pluralize(m.Left.ModelName)
1313
}
1414

1515
// RightNamePlural returns the pluralized version
16-
// of the "child" of the m2m relationship
16+
// of the "child" of the m2m relationship.
1717
func (m *ManyToManyDefinition) RightNamePlural() string {
1818
return inflect.Pluralize(m.Right.ModelName)
1919
}
2020

2121
// LeftName returns the name of the "owner" of the
22-
// m2m relationship
22+
// m2m relationship.
2323
func (m *ManyToManyDefinition) LeftName() string {
2424
return m.Left.ModelName
2525
}
2626

2727
// RightName returns the name of the "child" of the
28-
// m2m relationship
28+
// m2m relationship.
2929
func (m *ManyToManyDefinition) RightName() string {
3030
return m.Right.ModelName
3131
}
3232

3333
// LowerLeftName returns the lower case name of the "owner" of the
34-
// m2m relationship
34+
// m2m relationship.
3535
func (m *ManyToManyDefinition) LowerLeftName() string {
3636
return strings.ToLower(m.Left.ModelName)
3737
}
3838

3939
// LowerRightName returns the name of the "child" of the
40-
// m2m relationship
40+
// m2m relationship.
4141
func (m *ManyToManyDefinition) LowerRightName() string {
4242
return strings.ToLower(m.Right.ModelName)
4343
}

mapdefinition.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package gorma
22

33
// NewMapDefinition returns an initialized
4-
// MapDefinition
4+
// MapDefinition.
55
func NewMapDefinition() *MapDefinition {
66
return &MapDefinition{}
77
}

relationalfield.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
)
1111

1212
// NewRelationalFieldDefinition returns an initialized
13-
// RelationalFieldDefinition
13+
// RelationalFieldDefinition.
1414
func NewRelationalFieldDefinition() *RelationalFieldDefinition {
1515
m := &RelationalFieldDefinition{
1616
Mappings: make(map[string]*MapDefinition),
@@ -26,25 +26,24 @@ func (f *RelationalFieldDefinition) Context() string {
2626
return "unnamed RelationalField"
2727
}
2828

29-
// DSL returns this object's DSL
29+
// DSL returns this object's DSL.
3030
func (f *RelationalFieldDefinition) DSL() func() {
3131
return f.DefinitionDSL
3232
}
3333

34-
// Children returnsa slice of this objects children
34+
// Children returns a slice of this objects children.
3535
func (f RelationalFieldDefinition) Children() []dslengine.Definition {
3636
// no children yet
3737
return []dslengine.Definition{}
3838
}
3939

4040
// Attribute implements the Container interface of the goa Attribute
41-
// model
41+
// model.
4242
func (f *RelationalFieldDefinition) Attribute() *design.AttributeDefinition {
4343
return f.a
44-
4544
}
4645

47-
// FieldDefinition returns the field's struct definition
46+
// FieldDefinition returns the field's struct definition.
4847
func (f *RelationalFieldDefinition) FieldDefinition() string {
4948
var comment string
5049
if f.Description != "" {
@@ -54,7 +53,7 @@ func (f *RelationalFieldDefinition) FieldDefinition() string {
5453
return def
5554
}
5655

57-
// Tags returns the sql and gorm struct tags for the Definition
56+
// Tags returns the sql and gorm struct tags for the Definition.
5857
func (f *RelationalFieldDefinition) Tags() string {
5958
return tags(f)
6059
}
@@ -64,7 +63,7 @@ func (f *RelationalFieldDefinition) LowerName() string {
6463
return strings.ToLower(f.FieldName)
6564
}
6665

67-
// Underscore returns the field name as a lowercase string in snake case
66+
// Underscore returns the field name as a lowercase string in snake case.
6867
func (f *RelationalFieldDefinition) Underscore() string {
6968
return inflect.Underscore(f.FieldName)
7069
}

relationalmodel.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
)
1414

1515
// NewRelationalModelDefinition returns an initialized
16-
// RelationalModelDefinition
16+
// RelationalModelDefinition.
1717
func NewRelationalModelDefinition() *RelationalModelDefinition {
1818
baseAttr := &design.AttributeDefinition{}
1919
utd := &design.UserTypeDefinition{
@@ -48,7 +48,7 @@ func (f *RelationalModelDefinition) DSL() func() {
4848
return f.DefinitionDSL
4949
}
5050

51-
// TableName returns the TableName of the struct
51+
// TableName returns the TableName of the struct.
5252
func (f RelationalModelDefinition) TableName() string {
5353
return inflect.Underscore(inflect.Pluralize(f.ModelName))
5454
}
@@ -129,7 +129,9 @@ func (f *RelationalModelDefinition) Attribute() *design.AttributeDefinition {
129129

130130
}
131131

132-
// Project does something interesting, and I don't remember if I use it anywhere
132+
// Project does something interesting, and I don't remember if I use it
133+
// anywhere.
134+
//
133135
// TODO find out
134136
func (f *RelationalModelDefinition) Project(name, v string) *design.MediaTypeDefinition {
135137

@@ -217,7 +219,7 @@ func (f *RelationalModelDefinition) IterateFields(it FieldIterator) error {
217219

218220
// PopulateFromModeledType creates fields for the model
219221
// based on the goa UserTypeDefinition it models, which is
220-
// set using BuildsFrom()
222+
// set using BuildsFrom().
221223
// This happens before fields are processed, so it's
222224
// ok to just assign without testing.
223225
func (f *RelationalModelDefinition) PopulateFromModeledType() {

0 commit comments

Comments
 (0)