Last active
August 29, 2015 14:05
-
-
Save bulkan/c90be94df70c93faa89f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"net/http" | |
//"encoding/json" | |
"os" | |
"github.com/bitly/go-simplejson" | |
) | |
type NpmPackage struct { | |
Name, Description, Homepage, ReadmeFilename string | |
DistTags map[string]string `json:"dist-tags"` | |
Maintainers []map[string]string | |
Keywords []string | |
License interface{} | |
Repository, Author, Time, Bugs, Versions map[string]string | |
} | |
func main() { | |
// new Date().getTime() - 900000 | |
response, err := http.Get("http://registry.npmjs.org/-/all/since?stale=update_after&startkey=1407494718050") | |
if err != nil { | |
fmt.Printf("%s", err) | |
os.Exit(1) | |
} | |
defer response.Body.Close() | |
js, err := simplejson.NewFromReader(response.Body) | |
if err != nil { | |
panic(err) | |
} | |
p := js.Get("redisdown").Interface() | |
fmt.Println(p) | |
redisdown := p.(NpmPackage) | |
fmt.Printf("%s\n", redisdown.Maintainers[0]["email"]) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"net/http" | |
"encoding/json" | |
"os" | |
) | |
type NpmPackage struct { | |
Updated uint64 `json:"_updated"` | |
Name, Description, Homepage, ReadmeFilename string | |
DistTags map[string]string `json:"dist-tags"` | |
Maintainers []map[string]string | |
Keywords []string | |
License interface{} | |
Repository, Author, Time, Bugs, Versions map[string]string | |
} | |
type npmpackage NpmPackage | |
func (p *NpmPackage) UnmarshalJSON(b []byte) (err error){ | |
n, j := uint64(0), npmpackage{} | |
if err = json.Unmarshal(b, &n); err == nil { | |
p.Updated = n | |
return | |
} | |
if err = json.Unmarshal(b, &j); err == nil { | |
*p = NpmPackage(j) | |
return | |
} | |
return | |
} | |
func main() { | |
// new Date().getTime() - 900000 | |
response, err := http.Get("http://registry.npmjs.org/-/all/since?stale=update_after&startkey=1407494718050") | |
if err != nil { | |
fmt.Printf("%s", err) | |
os.Exit(1) | |
} | |
var packages map[string]NpmPackage | |
defer response.Body.Close() | |
if err := json.NewDecoder(response.Body).Decode(&packages); err != nil { | |
panic(err) | |
} | |
fmt.Printf("%s\n", packages["redisdown"].Maintainers[0]["email"]) | |
} |
Author
bulkan
commented
Aug 11, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment