Files
fx-serverless/middlewares/language.go
2020-03-11 08:59:47 +08:00

24 lines
499 B
Go

package middlewares
import (
"fmt"
"path/filepath"
"github.com/metrue/fx/constants"
"github.com/metrue/fx/context"
)
// Language to find out what language of function is
func Language() func(ctx context.Contexter) (err error) {
return func(ctx context.Contexter) error {
fn := ctx.Get("fn").(string)
ext := filepath.Ext(fn)
language, ok := constants.ExtLangMapping[ext]
if !ok {
return fmt.Errorf("%s not supported yet", ext)
}
ctx.Set("language", language)
return nil
}
}