0
0
mirror of https://gitea.com/gitea/docs.git synced 2025-05-11 00:35:06 +00:00
Files
appleboy dbfa0ba454 docs: add zh-tw folder (#195)
Signed-off-by: appleboy <appleboy.tw@gmail.com>
Reviewed-on: https://gitea.com/gitea/docs/pulls/195
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: appleboy <appleboy.tw@gmail.com>
Co-committed-by: appleboy <appleboy.tw@gmail.com>
2025-04-04 23:28:16 +00:00

67 lines
2.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
date: "2023-05-10T00:00:00+00:00"
slug: "go"
sidebar_position: 45
---
# Go 套件註冊表
為您的用戶或組織發布 Go 套件。
## 發布套件
要發布 Go 套件,請執行 HTTP `PUT` 操作,請求體中包含套件內容。
如果已經存在同名同版本的套件,您不能發布該套件。您必須先刪除現有的套件。
套件必須遵循[文檔結構](https://go.dev/ref/mod#zip-files)。
```
PUT https://gitea.example.com/api/packages/{owner}/go/upload
```
| 參數 | 描述 |
| ------- | -------------- |
| `owner` | 套件的擁有者。 |
要認證到套件註冊表,您需要提供[自定義 HTTP 標頭或使用 HTTP 基本認證](development/api-usage.md#authentication)
```shell
curl --user your_username:your_password_or_token \
--upload-file path/to/file.zip \
https://gitea.example.com/api/packages/testuser/go/upload
```
如果您使用 2FA 或 OAuth請使用 [個人訪問令牌](development/api-usage.md#authentication) 代替密碼。
如果已經存在同名同版本的套件,您不能發布該套件。您必須先刪除現有的套件。
服務器響應以下 HTTP 狀態碼。
| HTTP 狀態碼 | 含義 |
| ----------------- | -------------------------- |
| `201 Created` | 套件已發布。 |
| `400 Bad Request` | 套件無效。 |
| `409 Conflict` | 已存在具有相同名稱的套件。 |
## 安裝套件
要安裝 Go 套件,請指示 Go 使用套件註冊表作為代理:
```shell
# 使用最新版本
GOPROXY=https://gitea.example.com/api/packages/{owner}/go go install {package_name}
# 或者
GOPROXY=https://gitea.example.com/api/packages/{owner}/go go install {package_name}@latest
# 使用特定版本
GOPROXY=https://gitea.example.com/api/packages/{owner}/go go install {package_name}@{package_version}
```
| 參數 | 描述 |
| ----------------- | -------------- |
| `owner` | 套件的擁有者。 |
| `package_name` | 套件名稱。 |
| `package_version` | 套件版本。 |
如果套件的擁有者是私有的,您需要[提供憑證](https://go.dev/ref/mod#private-module-proxy-auth)。
有關 `GOPROXY` 環境變量以及如何防止數據洩漏的更多信息,請參閱[文檔](https://go.dev/ref/mod#private-modules)。