You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.3 KiB

package main
import (
"bytes"
"fmt"
"io"
"net/http"
)
func main() {
// Gitea API base URL
apiBaseURL := "https://01.kood.tech/git/api/v1"
// Your personal access token (replace with your own)
accessToken := "d2Ifgwill7fnota7epost89f7my6a163token3e5ha"
// Create a JSON request body
requestData := []byte(`{
"name": "short-and-memorable",
"private": false
}`)
// Create a new HTTP client
client := &http.Client{}
// Create a POST request
updateRepoURL := fmt.Sprintf("%s/user/repos", apiBaseURL)
req, err := http.NewRequest("POST", updateRepoURL, bytes.NewBuffer(requestData))
if err != nil {
fmt.Println("Error creating request:", err)
return
}
// Set the authorization header
req.Header.Set("Authorization", "token "+accessToken)
req.Header.Set("Content-Type", "application/json")
// Send the request
resp, err := client.Do(req)
if err != nil {
fmt.Println("Error sending request:", err)
return
}
defer resp.Body.Close()
// Read and display the response
responseData, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error reading response:", err)
return
}
if resp.Status == "200 OK" {
fmt.Println(string(responseData))
} else {
fmt.Printf("Failed to update repository: %s\n", resp.Status)
fmt.Println(string(responseData))
}
}