@@ -8,22 +8,24 @@ import (
88 "github.com/gin-gonic/gin"
99)
1010
11- //FnAnnotator Is used to inject trigger context (such as request URLs) into outbound trigger resources
11+ //FnAnnotator Is used to inject fn context (such as request URLs) into outbound fn resources
1212type FnAnnotator interface {
1313 // Annotates a trigger on read
1414 AnnotateFn (ctx * gin.Context , a * models.App , fn * models.Fn ) (* models.Fn , error )
1515}
1616
17- type requestBasedFnAnnotator struct {}
17+ type requestBasedFnAnnotator struct {
18+ group , template string
19+ }
1820
19- func annotateFnWithBaseURL (baseURL string , app * models.App , fn * models.Fn ) (* models.Fn , error ) {
21+ func annotateFnWithBaseURL (baseURL , group , template string , app * models.App , fn * models.Fn ) (* models.Fn , error ) {
2022
2123 baseURL = strings .TrimSuffix (baseURL , "/" )
22- src := strings .TrimPrefix ( fn .ID , "/" )
23- triggerPath := fmt .Sprintf ("%s/invoke/%s " , baseURL , src )
24+ path := strings .Replace ( template , ":fn_id" , fn .ID , - 1 )
25+ invokePath := fmt .Sprintf ("%s%s%s " , baseURL , group , path )
2426
2527 newT := fn .Clone ()
26- newAnnotations , err := newT .Annotations .With (models .FnInvokeEndpointAnnotation , triggerPath )
28+ newAnnotations , err := newT .Annotations .With (models .FnInvokeEndpointAnnotation , invokePath )
2729 if err != nil {
2830 return nil , err
2931 }
@@ -39,25 +41,25 @@ func (tp *requestBasedFnAnnotator) AnnotateFn(ctx *gin.Context, app *models.App,
3941 scheme = "https"
4042 }
4143
42- return annotateFnWithBaseURL (fmt .Sprintf ("%s://%s" , scheme , ctx .Request .Host ), app , t )
44+ return annotateFnWithBaseURL (fmt .Sprintf ("%s://%s" , scheme , ctx .Request .Host ), tp . group , tp . template , app , t )
4345}
4446
4547//NewRequestBasedFnAnnotator creates a FnAnnotator that inspects the incoming request host and port, and uses this to generate fn invoke endpoint URLs based on those
46- func NewRequestBasedFnAnnotator () FnAnnotator {
47- return & requestBasedFnAnnotator {}
48+ func NewRequestBasedFnAnnotator (group , template string ) FnAnnotator {
49+ return & requestBasedFnAnnotator {group : group , template : template }
4850}
4951
5052type staticURLFnAnnotator struct {
51- baseURL string
53+ baseURL , group , template string
5254}
5355
5456//NewStaticURLFnAnnotator annotates triggers bases on a given, specified URL base - e.g. "https://my.domain" ---> "https://my.domain/t/app/source"
55- func NewStaticURLFnAnnotator (baseURL string ) FnAnnotator {
57+ func NewStaticURLFnAnnotator (baseURL , group , template string ) FnAnnotator {
5658
57- return & staticURLFnAnnotator {baseURL : baseURL }
59+ return & staticURLFnAnnotator {baseURL : baseURL , group : group , template : template }
5860}
5961
6062func (s * staticURLFnAnnotator ) AnnotateFn (ctx * gin.Context , app * models.App , trigger * models.Fn ) (* models.Fn , error ) {
61- return annotateFnWithBaseURL (s .baseURL , app , trigger )
63+ return annotateFnWithBaseURL (s .baseURL , s . group , s . template , app , trigger )
6264
6365}
0 commit comments