@@ -308,20 +308,17 @@ const (
308308)
309309
310310// InvocationFollowResponseUnion contains all possible properties and values from
311- // [shared.LogEvent], [DeploymentStateEvent], [InvocationStateEvent],
312- // [shared.ErrorEvent].
311+ // [shared.LogEvent], [InvocationStateEvent], [shared.ErrorEvent].
313312//
314313// Use the [InvocationFollowResponseUnion.AsAny] method to switch on the variant.
315314//
316315// Use the methods beginning with 'As' to cast the union to one of its variants.
317316type InvocationFollowResponseUnion struct {
318- // Any of "log", nil, "invocation_state", "error".
317+ // Any of "log", "invocation_state", "error".
319318 Event string `json:"event"`
320319 // This field is from variant [shared.LogEvent].
321320 Message string `json:"message"`
322321 Timestamp time.Time `json:"timestamp"`
323- // This field is from variant [DeploymentStateEvent].
324- Deployment DeploymentStateEventDeployment `json:"deployment"`
325322 // This field is from variant [InvocationStateEvent].
326323 Invocation InvocationStateEventInvocation `json:"invocation"`
327324 // This field is from variant [shared.ErrorEvent].
@@ -330,19 +327,43 @@ type InvocationFollowResponseUnion struct {
330327 Event respjson.Field
331328 Message respjson.Field
332329 Timestamp respjson.Field
333- Deployment respjson.Field
334330 Invocation respjson.Field
335331 Error respjson.Field
336332 raw string
337333 } `json:"-"`
338334}
339335
340- func (u InvocationFollowResponseUnion ) AsLog () (v shared.LogEvent ) {
341- apijson .UnmarshalRoot (json .RawMessage (u .JSON .raw ), & v )
342- return
336+ // anyInvocationFollowResponse is implemented by each variant of
337+ // [InvocationFollowResponseUnion] to add type safety for the return type of
338+ // [InvocationFollowResponseUnion.AsAny]
339+ type anyInvocationFollowResponse interface {
340+ ImplInvocationFollowResponseUnion ()
343341}
344342
345- func (u InvocationFollowResponseUnion ) AsDeploymentStateEvent () (v DeploymentStateEvent ) {
343+ func (InvocationStateEvent ) ImplInvocationFollowResponseUnion () {}
344+
345+ // Use the following switch statement to find the correct variant
346+ //
347+ // switch variant := InvocationFollowResponseUnion.AsAny().(type) {
348+ // case shared.LogEvent:
349+ // case kernel.InvocationStateEvent:
350+ // case shared.ErrorEvent:
351+ // default:
352+ // fmt.Errorf("no variant present")
353+ // }
354+ func (u InvocationFollowResponseUnion ) AsAny () anyInvocationFollowResponse {
355+ switch u .Event {
356+ case "log" :
357+ return u .AsLog ()
358+ case "invocation_state" :
359+ return u .AsInvocationState ()
360+ case "error" :
361+ return u .AsError ()
362+ }
363+ return nil
364+ }
365+
366+ func (u InvocationFollowResponseUnion ) AsLog () (v shared.LogEvent ) {
346367 apijson .UnmarshalRoot (json .RawMessage (u .JSON .raw ), & v )
347368 return
348369}
0 commit comments