github.com/gitbundle/modules@v0.0.0-20231025071548-85b91c5c3b01/packages/container/oci/mediatype.go (about) 1 // Copyright 2023 The GitBundle Inc. All rights reserved. 2 // Copyright 2017 The Gitea Authors. All rights reserved. 3 // Use of this source code is governed by a MIT-style 4 // license that can be found in the LICENSE file. 5 6 package oci 7 8 import ( 9 "strings" 10 ) 11 12 const ( 13 MediaTypeImageManifest = "application/vnd.oci.image.manifest.v1+json" 14 MediaTypeImageIndex = "application/vnd.oci.image.index.v1+json" 15 MediaTypeDockerManifest = "application/vnd.docker.distribution.manifest.v2+json" 16 MediaTypeDockerManifestList = "application/vnd.docker.distribution.manifest.list.v2+json" 17 ) 18 19 type MediaType string 20 21 // IsValid tests if the media type is in the OCI or Docker namespace 22 func (m MediaType) IsValid() bool { 23 s := string(m) 24 return strings.HasPrefix(s, "application/vnd.docker.") || strings.HasPrefix(s, "application/vnd.oci.") 25 } 26 27 // IsImageManifest tests if the media type is an image manifest 28 func (m MediaType) IsImageManifest() bool { 29 s := string(m) 30 return strings.EqualFold(s, MediaTypeDockerManifest) || strings.EqualFold(s, MediaTypeImageManifest) 31 } 32 33 // IsImageIndex tests if the media type is an image index 34 func (m MediaType) IsImageIndex() bool { 35 s := string(m) 36 return strings.EqualFold(s, MediaTypeDockerManifestList) || strings.EqualFold(s, MediaTypeImageIndex) 37 }