@@ -923,10 +923,8 @@ func handleBuildContexts(r *http.Request, query url.Values, anchorDir string, mu
923923
924924 logrus .Debugf ("name: %q, context: %q" , name , value )
925925
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 )
930928 if err != nil {
931929 return nil , fmt .Errorf ("downloading URL %q: %w" , name , err )
932930 }
@@ -940,15 +938,14 @@ func handleBuildContexts(r *http.Request, query url.Values, anchorDir string, mu
940938 }
941939
942940 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 {
945942 out .AdditionalBuildContexts [name ] = & buildahDefine.AdditionalBuildContext {
946943 IsURL : false ,
947944 IsImage : true ,
948- Value : value ,
945+ Value : imageValue ,
949946 }
950947
951- logrus .Debugf ("Using image context %q: %q" , name , value )
948+ logrus .Debugf ("Using image context %q: %q" , name , imageValue )
952949 }
953950 }
954951
@@ -979,8 +976,7 @@ func handleBuildContexts(r *http.Request, query url.Values, anchorDir string, mu
979976
980977 fieldName := part .FormName ()
981978
982- switch {
983- case fieldName == "MainContext" :
979+ if fieldName == "MainContext" {
984980 mainDir , err := extractTarFile (anchorDir , part )
985981 if err != nil {
986982 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
989985 return nil , fmt .Errorf ("main context directory is empty" )
990986 }
991987 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 {
996989 // Create temp directory directly under anchorDir
997990 additionalAnchor , err := os .MkdirTemp (anchorDir , contextName + "-*" )
998991 if err != nil {
@@ -1039,7 +1032,7 @@ func handleBuildContexts(r *http.Request, query url.Values, anchorDir string, mu
10391032 IsImage : false ,
10401033 Value : additionalAnchor ,
10411034 }
1042- default :
1035+ } else {
10431036 logrus .Debugf ("Ignoring unknown multipart field: %s" , fieldName )
10441037 }
10451038 }
0 commit comments