@@ -10,15 +10,17 @@ type TriggerOptions struct {
1010 // Url of the workflow
1111 Url string
1212 // Body is the request payload of the new workflow run.
13- // It is expected to be either a string or JSON serializable object.
14- Body any
13+ Body []byte
1514 // RunId is the id of the new workflow run. If not provided, a random id will be generated
1615 RunId string
1716 // Retries is the number of retries if a step fails.
18- Retries * int
17+ Retries * int
18+ // FlowControlKey is the key used to control the flow of new steps.
1919 FlowControlKey string
20- Rate * int
21- Parallelism * int
20+ // Rate is the number of new starting steps per period.
21+ Rate int
22+ // Parallelism defines the maximum number of active steps associated with this FlowControlKey.
23+ Parallelism int
2224 // Header is the custom headers that will be forwarded to the workflow.
2325 Header http.Header
2426}
@@ -42,20 +44,25 @@ func (o *TriggerOptions) header() http.Header {
4244 header .Add (featureSetHeader , featureInitialBody )
4345 if o .FlowControlKey != "" {
4446 value := ""
45- if o .Rate != nil {
46- value += "rate=" + strconv .Itoa (* o .Rate )
47+ givenRate := o .Rate != 0
48+ if givenRate {
49+ value += fmt .Sprintf ("rate=%d" , o .Rate )
4750 }
48- if len ( value ) != 0 {
49- value += ","
50- }
51- if o . Parallelism != nil {
52- value += "parallelism=" + strconv . Itoa ( * o .Parallelism )
51+ if o . Parallelism != 0 {
52+ if givenRate {
53+ value += ","
54+ }
55+ value += fmt . Sprintf ( "parallelism=%d" , o .Parallelism )
5356 }
5457 if len (value ) > 0 {
5558 header .Set (flowControlKeyHeader , o .FlowControlKey )
5659 header .Set (flowControlValueHeader , value )
5760 }
5861 }
62+ if contentType := o .Header .Get (contentTypeHeader ); contentType != "" {
63+ header .Set (contentTypeHeader , contentType )
64+ o .Header .Del (contentTypeHeader )
65+ }
5966 header .Set (fmt .Sprintf ("%s%s" , forwardPrefix , sdkVersionHeader ), sdkVersion )
6067 for k , v := range o .Header {
6168 for _ , vv := range v {
@@ -77,15 +84,11 @@ func (c *Client) Trigger(opts TriggerOptions) (runId string, err error) {
7784 if err = opts .validate (); err != nil {
7885 return "" , fmt .Errorf ("failed to validate options: %w" , err )
7986 }
80- body , _ , err := serializeToStr (opts .Body )
81- if err != nil {
82- return "" , fmt .Errorf ("failed to serialize body: %w" , err )
83- }
8487 header := opts .header ()
8588 req := requestOptions {
8689 method : http .MethodPost ,
8790 path : []string {"v2" , "publish" , opts .Url },
88- body : body ,
91+ body : opts . Body ,
8992 header : header ,
9093 }
9194 resp , _ , err := c .do (req )
0 commit comments