Skip to content

Commit

Permalink
Use ast.IsExported
Browse files Browse the repository at this point in the history
  • Loading branch information
yuandrew committed Dec 6, 2024
1 parent 796352c commit b15cdd9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
10 changes: 3 additions & 7 deletions internal/cmd/tools/doclink/doclink.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func processPublic(cfg config, file *os.File) (map[string]string, error) {
for _, spec := range genDecl.Specs {
if typeSpec, typeOk := spec.(*ast.TypeSpec); typeOk {
name := typeSpec.Name.Name
if isPublic(name) {
if ast.IsExported(name) {
res := extractTypeValue(typeSpec.Type)
if len(res) > 0 {
publicToInternal[name] = res
Expand All @@ -182,7 +182,7 @@ func processPublic(cfg config, file *os.File) (map[string]string, error) {
return true
}
name := valueSpec.Names
if isPublic(name[0].Name) {
if ast.IsExported(name[0].Name) {
res := checkValueSpec(valueSpec)
if len(res) > 0 {
publicToInternal[name[0].Name] = res
Expand All @@ -191,7 +191,7 @@ func processPublic(cfg config, file *os.File) (map[string]string, error) {
}
}
}
if funcDecl, ok := n.(*ast.FuncDecl); ok && isPublic(funcDecl.Name.Name) {
if funcDecl, ok := n.(*ast.FuncDecl); ok && ast.IsExported(funcDecl.Name.Name) {
isWrapper := checkFunction(funcDecl)
if len(isWrapper) > 0 {
publicToInternal[funcDecl.Name.Name] = isWrapper
Expand All @@ -202,10 +202,6 @@ func processPublic(cfg config, file *os.File) (map[string]string, error) {
return publicToInternal, nil
}

func isPublic(name string) bool {
return strings.ToUpper(string(name[0])) == string(name[0])
}

func extractTypeValue(expr ast.Expr) string {
switch t := expr.(type) {
case *ast.StructType:
Expand Down
47 changes: 47 additions & 0 deletions internal/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import (
// the interceptor package for more details.
//
// Exposed as: [go.temporal.io/sdk/interceptor.Interceptor]
//
// Exposed as: [go.temporal.io/sdk/interceptor.Interceptor]
type Interceptor interface {
ClientInterceptor
WorkerInterceptor
Expand All @@ -48,6 +50,8 @@ type Interceptor interface {
// documentation in the interceptor package for more details.
//
// Exposed as: [go.temporal.io/sdk/interceptor.WorkerInterceptor]
//
// Exposed as: [go.temporal.io/sdk/interceptor.WorkerInterceptor]
type WorkerInterceptor interface {
// InterceptActivity is called before each activity interception needed with
// the next interceptor in the chain.
Expand All @@ -65,6 +69,8 @@ type WorkerInterceptor interface {
// details.
//
// Exposed as: [go.temporal.io/sdk/interceptor.ActivityInboundInterceptor]
//
// Exposed as: [go.temporal.io/sdk/interceptor.ActivityInboundInterceptor]
type ActivityInboundInterceptor interface {
// Init is the first call of this interceptor. Implementations can change/wrap
// the outbound interceptor before calling Init on the next interceptor.
Expand All @@ -80,6 +86,8 @@ type ActivityInboundInterceptor interface {
// ExecuteActivityInput is the input to ActivityInboundInterceptor.ExecuteActivity.
//
// Exposed as: [go.temporal.io/sdk/interceptor.ExecuteActivityInput]
//
// Exposed as: [go.temporal.io/sdk/interceptor.ExecuteActivityInput]
type ExecuteActivityInput struct {
Args []interface{}
}
Expand All @@ -89,6 +97,8 @@ type ExecuteActivityInput struct {
// more details.
//
// Exposed as: [go.temporal.io/sdk/interceptor.ActivityOutboundInterceptor]
//
// Exposed as: [go.temporal.io/sdk/interceptor.ActivityOutboundInterceptor]
type ActivityOutboundInterceptor interface {
// GetInfo intercepts activity.GetInfo.
GetInfo(ctx context.Context) ActivityInfo
Expand Down Expand Up @@ -119,6 +129,8 @@ type ActivityOutboundInterceptor interface {
// details.
//
// Exposed as: [go.temporal.io/sdk/interceptor.WorkflowInboundInterceptor]
//
// Exposed as: [go.temporal.io/sdk/interceptor.WorkflowInboundInterceptor]
type WorkflowInboundInterceptor interface {
// Init is the first call of this interceptor. Implementations can change/wrap
// the outbound interceptor before calling Init on the next interceptor.
Expand Down Expand Up @@ -160,13 +172,17 @@ type WorkflowInboundInterceptor interface {
// WorkflowInboundInterceptor.ExecuteWorkflow.
//
// Exposed as: [go.temporal.io/sdk/interceptor.ExecuteWorkflowInput]
//
// Exposed as: [go.temporal.io/sdk/interceptor.ExecuteWorkflowInput]
type ExecuteWorkflowInput struct {
Args []interface{}
}

// HandleSignalInput is the input to WorkflowInboundInterceptor.HandleSignal.
//
// Exposed as: [go.temporal.io/sdk/interceptor.HandleSignalInput]
//
// Exposed as: [go.temporal.io/sdk/interceptor.HandleSignalInput]
type HandleSignalInput struct {
SignalName string
// Arg is the signal argument. It is presented as a primitive payload since
Expand All @@ -177,6 +193,8 @@ type HandleSignalInput struct {
// UpdateInput carries the name and arguments of a workflow update invocation.
//
// Exposed as: [go.temporal.io/sdk/interceptor.UpdateInput]
//
// Exposed as: [go.temporal.io/sdk/interceptor.UpdateInput]
type UpdateInput struct {
Name string
Args []interface{}
Expand All @@ -185,6 +203,8 @@ type UpdateInput struct {
// HandleQueryInput is the input to WorkflowInboundInterceptor.HandleQuery.
//
// Exposed as: [go.temporal.io/sdk/interceptor.HandleQueryInput]
//
// Exposed as: [go.temporal.io/sdk/interceptor.HandleQueryInput]
type HandleQueryInput struct {
QueryType string
Args []interface{}
Expand All @@ -195,6 +215,8 @@ type HandleQueryInput struct {
// NOTE: Experimental
//
// Exposed as: [go.temporal.io/sdk/interceptor.ExecuteNexusOperationInput]
//
// Exposed as: [go.temporal.io/sdk/interceptor.ExecuteNexusOperationInput]
type ExecuteNexusOperationInput struct {
// Client to start the operation with.
Client NexusClient
Expand All @@ -213,6 +235,8 @@ type ExecuteNexusOperationInput struct {
// NOTE: Experimental
//
// Exposed as: [go.temporal.io/sdk/interceptor.RequestCancelNexusOperationInput]
//
// Exposed as: [go.temporal.io/sdk/interceptor.RequestCancelNexusOperationInput]
type RequestCancelNexusOperationInput struct {
// Client that was used to start the operation.
Client NexusClient
Expand All @@ -229,6 +253,8 @@ type RequestCancelNexusOperationInput struct {
// more details.
//
// Exposed as: [go.temporal.io/sdk/interceptor.WorkflowOutboundInterceptor]
//
// Exposed as: [go.temporal.io/sdk/interceptor.WorkflowOutboundInterceptor]
type WorkflowOutboundInterceptor interface {
// Go intercepts workflow.Go.
Go(ctx Context, name string, f func(ctx Context)) Context
Expand Down Expand Up @@ -378,6 +404,8 @@ type WorkflowOutboundInterceptor interface {
// interceptor package for more details.
//
// Exposed as: [go.temporal.io/sdk/interceptor.ClientInterceptor]
//
// Exposed as: [go.temporal.io/sdk/interceptor.ClientInterceptor]
type ClientInterceptor interface {
// This is called on client creation if set via client options
InterceptClient(next ClientOutboundInterceptor) ClientOutboundInterceptor
Expand All @@ -390,6 +418,8 @@ type ClientInterceptor interface {
// more details.
//
// Exposed as: [go.temporal.io/sdk/interceptor.ClientOutboundInterceptor]
//
// Exposed as: [go.temporal.io/sdk/interceptor.ClientOutboundInterceptor]
type ClientOutboundInterceptor interface {
// ExecuteWorkflow intercepts client.Client.ExecuteWorkflow.
// interceptor.Header will return a non-nil map for this context.
Expand Down Expand Up @@ -443,6 +473,8 @@ type ClientOutboundInterceptor interface {
// NOTE: Experimental
//
// Exposed as: [go.temporal.io/sdk/interceptor.ClientUpdateWorkflowInput]
//
// Exposed as: [go.temporal.io/sdk/interceptor.ClientUpdateWorkflowInput]
type ClientUpdateWorkflowInput struct {
UpdateID string
WorkflowID string
Expand All @@ -453,6 +485,7 @@ type ClientUpdateWorkflowInput struct {
WaitForStage WorkflowUpdateStage
}

// Exposed as: [go.temporal.io/sdk/interceptor.ClientUpdateWithStartWorkflowInput]
type ClientUpdateWithStartWorkflowInput struct {
UpdateOptions *UpdateWorkflowOptions
StartWorkflowOperation WithStartWorkflowOperation
Expand All @@ -477,6 +510,8 @@ type ClientPollWorkflowUpdateOutput struct {
// ClientOutboundInterceptor.CreateSchedule.
//
// Exposed as: [go.temporal.io/sdk/interceptor.ScheduleClientCreateInput]
//
// Exposed as: [go.temporal.io/sdk/interceptor.ScheduleClientCreateInput]
type ScheduleClientCreateInput struct {
Options *ScheduleOptions
}
Expand All @@ -485,6 +520,8 @@ type ScheduleClientCreateInput struct {
// ClientOutboundInterceptor.ExecuteWorkflow.
//
// Exposed as: [go.temporal.io/sdk/interceptor.ClientExecuteWorkflowInput]
//
// Exposed as: [go.temporal.io/sdk/interceptor.ClientExecuteWorkflowInput]
type ClientExecuteWorkflowInput struct {
Options *StartWorkflowOptions
WorkflowType string
Expand All @@ -495,6 +532,8 @@ type ClientExecuteWorkflowInput struct {
// ClientOutboundInterceptor.SignalWorkflow.
//
// Exposed as: [go.temporal.io/sdk/interceptor.ClientSignalWorkflowInput]
//
// Exposed as: [go.temporal.io/sdk/interceptor.ClientSignalWorkflowInput]
type ClientSignalWorkflowInput struct {
WorkflowID string
RunID string
Expand All @@ -506,6 +545,8 @@ type ClientSignalWorkflowInput struct {
// ClientOutboundInterceptor.SignalWithStartWorkflow.
//
// Exposed as: [go.temporal.io/sdk/interceptor.ClientSignalWithStartWorkflowInput]
//
// Exposed as: [go.temporal.io/sdk/interceptor.ClientSignalWithStartWorkflowInput]
type ClientSignalWithStartWorkflowInput struct {
SignalName string
SignalArg interface{}
Expand All @@ -518,6 +559,8 @@ type ClientSignalWithStartWorkflowInput struct {
// ClientOutboundInterceptor.CancelWorkflow.
//
// Exposed as: [go.temporal.io/sdk/interceptor.ClientCancelWorkflowInput]
//
// Exposed as: [go.temporal.io/sdk/interceptor.ClientCancelWorkflowInput]
type ClientCancelWorkflowInput struct {
WorkflowID string
RunID string
Expand All @@ -527,6 +570,8 @@ type ClientCancelWorkflowInput struct {
// ClientOutboundInterceptor.TerminateWorkflow.
//
// Exposed as: [go.temporal.io/sdk/interceptor.ClientTerminateWorkflowInput]
//
// Exposed as: [go.temporal.io/sdk/interceptor.ClientTerminateWorkflowInput]
type ClientTerminateWorkflowInput struct {
WorkflowID string
RunID string
Expand All @@ -538,6 +583,8 @@ type ClientTerminateWorkflowInput struct {
// ClientOutboundInterceptor.QueryWorkflow.
//
// Exposed as: [go.temporal.io/sdk/interceptor.ClientQueryWorkflowInput]
//
// Exposed as: [go.temporal.io/sdk/interceptor.ClientQueryWorkflowInput]
type ClientQueryWorkflowInput struct {
WorkflowID string
RunID string
Expand Down

0 comments on commit b15cdd9

Please sign in to comment.