Skip to content

Commit faffd7c

Browse files
brucearctorbrucearctor
authored andcommitted
Add missing documentation for exposed structs in internal package
1 parent d41dc8e commit faffd7c

12 files changed

Lines changed: 252 additions & 6 deletions

internal/activity.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@ type (
1818
//
1919
// Exposed as: [go.temporal.io/sdk/activity.Type]
2020
ActivityType struct {
21+
// Name is the name of the activity type.
2122
Name string
2223
}
2324

2425
// ActivityInfo contains information about a currently executing activity.
2526
//
2627
// Exposed as: [go.temporal.io/sdk/activity.Info]
2728
ActivityInfo struct {
29+
// TaskToken is the token that identifies the activity task.
2830
TaskToken []byte
31+
// WorkflowType is the type of the workflow that started this activity.
2932
WorkflowType *WorkflowType
3033
// Namespace of the workflow that started this activity. Empty if this activity was not started by a workflow.
3134
// If present, the value is always the same as Namespace since workflows can only run activities in their own
@@ -36,9 +39,13 @@ type (
3639
// Execution details of the workflow that started this activity. All fields are empty if this activity was not
3740
// started by a workflow.
3841
WorkflowExecution WorkflowExecution
42+
// ActivityID is the ID of the activity.
3943
ActivityID string
44+
// ActivityRunID is the run ID of the activity. Empty if the activity was started by a workflow.
4045
ActivityRunID string // Run ID of the activity. Empty if the activity was started by a workflow.
46+
// ActivityType is the type of the activity.
4147
ActivityType ActivityType
48+
// TaskQueue is the name of the task queue that the activity needs to be scheduled on.
4249
TaskQueue string
4350
Namespace string // Namespace of this activity.
4451
HeartbeatTimeout time.Duration // Maximum time between heartbeats. 0 means no heartbeat needed.
@@ -73,6 +80,7 @@ type (
7380
// ambiguity between string names and function references. Also users should
7481
// always use this string name when executing this activity.
7582
Name string
83+
// DisableAlreadyRegisteredCheck disables the check for already registered activities.
7684
DisableAlreadyRegisteredCheck bool
7785

7886
// When registering a struct with activities, skip functions that are not valid activities. If false,

internal/cmd/tools/doclink/doclink.go

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ func run() error {
127127
if err != nil {
128128
return fmt.Errorf("error while parsing internal files: %v", err)
129129
}
130+
131+
err = checkInternalDocs(path, file, publicToInternal)
132+
if err != nil {
133+
return fmt.Errorf("error while checking internal docs: %v", err)
134+
}
130135
}
131136
return nil
132137
})
@@ -587,3 +592,84 @@ func isValidDefinitionWithMatch(line, private string, inGroup string, insideStru
587592
}
588593
return false
589594
}
595+
596+
func checkInternalDocs(path string, file *os.File, pairs map[string]map[string]string) error {
597+
fs := token.NewFileSet()
598+
599+
// Reset file pointer to start
600+
_, err := file.Seek(0, 0)
601+
if err != nil {
602+
return fmt.Errorf("failed to seek: %v", err)
603+
}
604+
605+
node, err := parser.ParseFile(fs, path, file, parser.ParseComments)
606+
if err != nil {
607+
return fmt.Errorf("failed to parse file %s: %v", path, err)
608+
}
609+
610+
exposedTypes := make(map[string]bool)
611+
for _, pair := range pairs {
612+
for _, private := range pair {
613+
exposedTypes[private] = true
614+
}
615+
}
616+
617+
ast.Inspect(node, func(n ast.Node) bool {
618+
if genDecl, ok := n.(*ast.GenDecl); ok && genDecl.Tok == token.TYPE {
619+
for _, spec := range genDecl.Specs {
620+
if typeSpec, ok := spec.(*ast.TypeSpec); ok {
621+
if !exposedTypes[typeSpec.Name.Name] {
622+
continue
623+
}
624+
if structType, ok := typeSpec.Type.(*ast.StructType); ok {
625+
for _, field := range structType.Fields.List {
626+
isExported := false
627+
var fieldName string
628+
if len(field.Names) > 0 {
629+
for _, name := range field.Names {
630+
if ast.IsExported(name.Name) {
631+
isExported = true
632+
fieldName = name.Name
633+
break
634+
}
635+
}
636+
} else {
637+
// Check anonymous field
638+
if ident, ok := field.Type.(*ast.Ident); ok {
639+
if ast.IsExported(ident.Name) {
640+
isExported = true
641+
fieldName = ident.Name
642+
}
643+
} else if sel, ok := field.Type.(*ast.SelectorExpr); ok {
644+
if ast.IsExported(sel.Sel.Name) {
645+
isExported = true
646+
fieldName = sel.Sel.Name
647+
}
648+
} else if star, ok := field.Type.(*ast.StarExpr); ok {
649+
if ident, ok := star.X.(*ast.Ident); ok {
650+
if ast.IsExported(ident.Name) {
651+
isExported = true
652+
fieldName = ident.Name
653+
}
654+
} else if sel, ok := star.X.(*ast.SelectorExpr); ok {
655+
if ast.IsExported(sel.Sel.Name) {
656+
isExported = true
657+
fieldName = sel.Sel.Name
658+
}
659+
}
660+
}
661+
}
662+
663+
if isExported && field.Doc == nil && field.Comment == nil {
664+
changesNeeded = true
665+
fmt.Printf("Missing doc for exposed struct %s field %s in %s\n", typeSpec.Name.Name, fieldName, path)
666+
}
667+
}
668+
}
669+
}
670+
}
671+
}
672+
return true
673+
})
674+
return nil
675+
}

internal/error.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,17 @@ type (
193193
// Exposed as: [go.temporal.io/sdk/workflow.ContinueAsNewError]
194194
ContinueAsNewError struct {
195195
// params *ExecuteWorkflowParams
196+
// WorkflowType is the type of the workflow.
196197
WorkflowType *WorkflowType
198+
// Input is the payload of the workflow.
197199
Input *commonpb.Payloads
200+
// Header is the header of the workflow.
198201
Header *commonpb.Header
202+
// TaskQueueName is the task queue that the workflow is running on.
199203
TaskQueueName string
204+
// WorkflowRunTimeout is the timeout for a single run of the workflow execution.
200205
WorkflowRunTimeout time.Duration
206+
// WorkflowTaskTimeout is the maximum execution time of a single Workflow Task.
201207
WorkflowTaskTimeout time.Duration
202208

203209
// Deprecated: WorkflowExecutionTimeout is deprecated and is never set or

0 commit comments

Comments
 (0)