@@ -923,10 +923,8 @@ func handleBuildContexts(r *http.Request, query url.Values, anchorDir string, mu
923
923
924
924
logrus .Debugf ("name: %q, context: %q" , name , value )
925
925
926
- switch {
927
- case strings .HasPrefix (value , "url:" ):
928
- value = strings .TrimPrefix (value , "url:" )
929
- tempDir , subdir , err := buildahDefine .TempDirForURL (anchorDir , "buildah" , value )
926
+ if urlValue , ok := strings .CutPrefix (value , "url:" ); ok {
927
+ tempDir , subdir , err := buildahDefine .TempDirForURL (anchorDir , "buildah" , urlValue )
930
928
if err != nil {
931
929
return nil , fmt .Errorf ("downloading URL %q: %w" , name , err )
932
930
}
@@ -940,15 +938,14 @@ func handleBuildContexts(r *http.Request, query url.Values, anchorDir string, mu
940
938
}
941
939
942
940
logrus .Debugf ("Downloaded URL context %q to %q" , name , contextPath )
943
- case strings .HasPrefix (value , "image:" ):
944
- value = strings .TrimPrefix (value , "image:" )
941
+ } else if imageValue , ok := strings .CutPrefix (value , "image:" ); ok {
945
942
out .AdditionalBuildContexts [name ] = & buildahDefine.AdditionalBuildContext {
946
943
IsURL : false ,
947
944
IsImage : true ,
948
- Value : value ,
945
+ Value : imageValue ,
949
946
}
950
947
951
- logrus .Debugf ("Using image context %q: %q" , name , value )
948
+ logrus .Debugf ("Using image context %q: %q" , name , imageValue )
952
949
}
953
950
}
954
951
@@ -979,8 +976,7 @@ func handleBuildContexts(r *http.Request, query url.Values, anchorDir string, mu
979
976
980
977
fieldName := part .FormName ()
981
978
982
- switch {
983
- case fieldName == "MainContext" :
979
+ if fieldName == "MainContext" {
984
980
mainDir , err := extractTarFile (anchorDir , part )
985
981
if err != nil {
986
982
return nil , fmt .Errorf ("extracting main context in multipart: %w" , err )
@@ -989,10 +985,7 @@ func handleBuildContexts(r *http.Request, query url.Values, anchorDir string, mu
989
985
return nil , fmt .Errorf ("main context directory is empty" )
990
986
}
991
987
out .ContextDirectory = mainDir
992
-
993
- case strings .HasPrefix (fieldName , "build-context-" ):
994
- contextName := strings .TrimPrefix (fieldName , "build-context-" )
995
-
988
+ } else if contextName , ok := strings .CutPrefix (fieldName , "build-context-" ); ok {
996
989
// Create temp directory directly under anchorDir
997
990
additionalAnchor , err := os .MkdirTemp (anchorDir , contextName + "-*" )
998
991
if err != nil {
@@ -1039,7 +1032,7 @@ func handleBuildContexts(r *http.Request, query url.Values, anchorDir string, mu
1039
1032
IsImage : false ,
1040
1033
Value : additionalAnchor ,
1041
1034
}
1042
- default :
1035
+ } else {
1043
1036
logrus .Debugf ("Ignoring unknown multipart field: %s" , fieldName )
1044
1037
}
1045
1038
}
0 commit comments