/
main.go
executable file
·52 lines (42 loc) · 1.3 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import "strconv"
import "fmt"
import "crypto/rsa"
import "crypto/rand"
import "github.com/google/go-querystring/query"
import "github.com/google/go-github/github"
import "github.com/square/go-jose"
type Options struct {
Query string `url:"q"`
ShowAll bool `url:"all"`
Page int `url:"page"`
}
func main() {
// Use go-querystring
fmt.Println("Intro to Go!")
opt := Options{ "foo", true, 2 }
v, _ := query.Values(opt)
fmt.Println(v.Encode()) // will output: "q=foo&all=true&page=2"
// Use go-github
client := github.NewClient(nil)
// list public repositories for org "github"
publicRepos := &github.RepositoryListByOrgOptions{Type: "public"}
repos, _, _ := client.Repositories.ListByOrg("github", publicRepos)
fmt.Println("Hello from sub! Num repos: " + strconv.Itoa(len(repos)))
// Use go-jose
privateKey, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
panic(err)
}
publicKey := &privateKey.PublicKey
encrypter, err := jose.NewEncrypter(jose.RSA_OAEP, jose.A128GCM, publicKey)
if err != nil {
panic(err)
}
var plaintext = []byte("Lorem ipsum dolor sit amet")
object, err := encrypter.Encrypt(plaintext)
if err != nil {
panic(err)
}
fmt.Println(object)
}