Hi, I am coding a script that gets all my issues on Github from a specific repo.
This is the script that I am using to do it
package main
import (
"context"
"log"
"github.com/google/go-github/github"
"golang.org/x/oauth2"
)
func main() {
ctx := context.Background()
tokenSource := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: "my-token"},
)
// Authentication on Github using GH Token
tokenClient := oauth2.NewClient(ctx, tokenSource)
client := github.NewClient(tokenClient)
// Parsing response from GH
resp, _, err := client.Issues.ListByRepo(ctx, "orgID", "repoID", nil)
if err != nil {
log.Fatal(err)
}
log.Println(resp)
}
PS: Sorry if I did any mistake, it's my first Go script :smile:
When I checked the JSON that came from resp, _, err := client.Issues.ListByRepo(ctx, "orgID", "repoID", nil) I see one field empty, fields related to time type, it is CreatedAt and UpdatedAt (I still haven't CloseAt cause the issue is still Open :yum: )
JSON returned values:
...
Comments: 0,
CreatedAt:time.Time{wall: , ext:},
UpdatedAt:time.Time{wall: , ext:},
URL: "https://api.github...."
...
I took a look at Golang pkg/time documentation and I see it:
Programs using times should typically store and pass them as values, not pointers. That is, time variables and struct fields should be of type time.Time, not *time.Time. REF: type Time
What I could see at Issue struct definition was it uses CreatedAt *time.Time json:"created_at,omitempty" check it here
As I am at the beginner stage on Golang, I do not if it is right or it doesn't.
Could you guys clarify my question?
Thanks!
Hi @kassyuz and welcome to Go! 馃槃
Can you please tell us what version of this repo you are using?
Also, while I'm here, one quick way to debug things like this is to use curl to see what the full JSON response is, or just instrument github/github.go and dump out the full response. Then you can see what is coming back across the wire.
Hi @kassyuz and welcome to Go!
Can you please tell us what version of this repo you are using?
Golang: go version go1.12.5 linux/amd64
Regarding the repo version, I am using 26.0.4
Also, while I'm here, one quick way to debug things like this is to use
curlto see what the full JSON response is, or just instrumentgithub/github.goand dump out the full response. Then you can see what is coming back across the wire.
@gmlewis I have a script (in Python) invoking the same GH API function and over there I can see all values from CreatedAt and UpdatedAt
Return from GH API V3 using Python:
2019-06-14T14:20:30Z
2019-06-14T13:22:59Z
BTW, I am gonna try out instrument github/github.go and check what will be the difference.
Closing due to inactivity. Feel free to reopen if needed.
Most helpful comment
@gmlewis I have a script (in Python) invoking the same GH API function and over there I can see all values from
CreatedAtandUpdatedAtReturn from GH API V3 using Python:
BTW, I am gonna try out instrument
github/github.goand check what will be the difference.