--- /dev/null
+/*
+GoCheese -- Python private package repository and caching proxy
+Copyright (C) 2019-2021 Sergey Matveev <stargrave@stargrave.org>
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, version 3 of the License.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+package main
+
+import "strings"
+
+const (
+ MetadataFile = ".metadata.rec"
+
+ // https://packaging.python.org/specifications/core-metadata/
+ MetadataVersion = "2.1"
+ MetadataFieldMetadataVersion = "Metadata-Version"
+ MetadataFieldName = "Name"
+ MetadataFieldVersion = "Version"
+ MetadataFieldDescription = "Description"
+ MetadataFieldPlatform = "Platform"
+ MetadataFieldSupportedPlatform = "Supported-Platform"
+ MetadataFieldSummary = "Summary"
+ MetadataFieldDescriptionContentType = "Description-Content-Type"
+ MetadataFieldKeywords = "Keywords"
+ MetadataFieldHomePage = "Home-page"
+ MetadataFieldAuthor = "Author"
+ MetadataFieldAuthorEmail = "Author-email"
+ MetadataFieldMaintainer = "Maintainer"
+ MetadataFieldMaintainerEmail = "Maintainer-Email"
+ MetadataFieldLicense = "License"
+ MetadataFieldRequiresDist = "Requires-Dist"
+ MetadataFieldRequiresPython = "Requires-Python"
+ MetadataFieldRequiresExternal = "Requires-External"
+ MetadataFieldProjectURL = "Project-URL"
+ MetadataFieldProvidesExtra = "Provides-Extra"
+ MetadataFieldClassifier = "Classifier"
+)
+
+func metadataFieldToRecField(f string) string {
+ return strings.ReplaceAll(f, "-", "")
+}
+
+// It should follow https://www.python.org/dev/peps/pep-0566/
+type PkgInfo struct {
+ Name string `json:"name"`
+ Version string `json:"version"`
+ Platform []string `json:"platform,omitempty"`
+ SupportedPlatform []string `json:"supported_platform,omitempty"`
+ Summary string `json:"summary,omitempty"`
+ Description string `json:"description,omitempty"`
+ DescriptionContentType string `json:"description_content_type,omitempty"`
+ Keywords string `json:"keywords,omitempty"`
+ HomePage string `json:"home_page,omitempty"`
+ Author string `json:"author,omitempty"`
+ AuthorEmail string `json:"author_email,omitempty"`
+ Maintainer string `json:"maintainer,omitempty"`
+ MaintainerEmail string `json:"maintainer_email,omitempty"`
+ License string `json:"license,omitempty"`
+ Classifier []string `json:"classifier,omitempty"`
+ RequiresDist []string `json:"requires_dist,omitempty"`
+ RequiresPython string `json:"requires_python,omitempty"`
+ RequiresExternal []string `json:"requires_external,omitempty"`
+ ProjectURL []string `json:"project_url,omitempty"`
+ ProvidesExtra []string `json:"provides_extra,omitempty"`
+}
+
+// But current PyPI does not follow PEP-0566, so just ignore some fields
+type PkgInfoStripped struct {
+ Name string `json:"name"`
+ Version string `json:"version"`
+ Summary string `json:"summary,omitempty"`
+ Description string `json:"description,omitempty"`
+ DescriptionContentType string `json:"description_content_type,omitempty"`
+ Keywords string `json:"keywords,omitempty"`
+ HomePage string `json:"home_page,omitempty"`
+ Author string `json:"author,omitempty"`
+ AuthorEmail string `json:"author_email,omitempty"`
+ Maintainer string `json:"maintainer,omitempty"`
+ MaintainerEmail string `json:"maintainer_email,omitempty"`
+ License string `json:"license,omitempty"`
+ Classifier []string `json:"classifiers,omitempty"`
+ RequiresPython string `json:"requires_python,omitempty"`
+ RequiresDist []string `json:"requires_dist,omitempty"`
+}
+
+// Unknown format: no detailed specification available
+// https://github.com/cooperlees/peps/blob/warehouse_json_api/pep-9999.rst
+type PkgReleaseInfo struct {
+ Filename string `json:"filename"`
+ Version string `json:"version"`
+ UploadTimeISO8601 string `json:"upload_time_iso_8601"`
+ Size int64 `json:"size"`
+ HasSig bool `json:"has_sig"`
+
+ Digests map[string]string `json:"digests"`
+}
+
+type PkgMeta struct {
+ Info PkgInfo `json:"info"`
+ LastSerial int `json:"last_serial"`
+ Releases map[string][]*PkgReleaseInfo `json:"releases"`
+ URLs []*PkgReleaseInfo `json:"urls"`
+}
+
+type PkgMetaStripped struct {
+ Info PkgInfoStripped `json:"info"`
+ Releases map[string][]*PkgReleaseInfo `json:"releases"`
+}