Browse Source

public

master
Mikk Adler 8 months ago
commit
ba3d8cd954
  1. 59
      giteaAPI.go
  2. 3
      go.mod

59
giteaAPI.go

@ -0,0 +1,59 @@
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))
}
}

3
go.mod

@ -0,0 +1,3 @@
module main
go 1.21.1
Loading…
Cancel
Save