This commit is contained in:
a.pivkin
2025-12-27 18:55:08 +03:00
parent 0124fc6ace
commit c1bae790ed
3 changed files with 100 additions and 18 deletions
+47 -18
View File
@@ -1,30 +1,59 @@
package main
import (
"encoding/json"
"fmt"
"strconv"
"go.uber.org/zap/buffer"
"io"
"net/http"
"os"
"time"
)
func addCommas(n int) string {
str := strconv.Itoa(n)
// Add commas from right to left
var result buffer.Buffer
for i := range str {
if i > 0 && (len(str)-i)%3 == 0 {
fmt.Fprint(&result,",")
}
result.WriteByte(str[i])
const URL = "https://api.github.com/search/issues"
type IssuerSearchReport struct {
Total int `json:"total_count"`
Incomplete_results bool `json:"incomplete_results"`
Created_at time.Time `json:"created_at"`
Items []Issue
}
type Issue struct {
Title string `json:"title"`
User User
}
type User struct {
Login string `json:"login"`
}
func IssuerSearch(s []string) (IssuerSearchReport,error) {
new_s := s[0]
resp,err := http.Get(URL + "?q=" + new_s)
if err != nil {
return IssuerSearchReport{},err
}
return result.String()
if resp.StatusCode != http.StatusOK {
resp.Body.Close()
return IssuerSearchReport{},fmt.Errorf("Error in request",resp.Status)
}
var result IssuerSearchReport
body,_ := io.ReadAll(resp.Body)
if err := json.Unmarshal(body,&result); err != nil {
resp.Body.Close()
return IssuerSearchReport{},nil
}
resp.Body.Close()
return result,nil
}
func main() {
numbers := []int{12345, 1234567, 987654321, 12345, 123, 0}
for _, num := range numbers {
fmt.Printf("%d -> %s\n", num, addCommas(num))
result,err := IssuerSearch(os.Args[1:])
if err != nil {
fmt.Println("Error in IssuerSearch")
}
fmt.Printf("%#v\n",result)
fmt.Println(result)
}