Mikk Adler
8 months ago
commit
ba3d8cd954
2 changed files with 62 additions and 0 deletions
@ -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)) |
||||
} |
||||
} |
@ -0,0 +1,3 @@
|
||||
module main |
||||
|
||||
go 1.21.1 |
Loading…
Reference in new issue