-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
50 lines (39 loc) · 950 Bytes
/
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
package main
import (
"fmt"
"os"
"github.com/lukakerr/hkn"
)
func _main() int {
username := os.Getenv("INPUT_HN_USERNAME")
password := os.Getenv("INPUT_HN_PASSWORD")
title := os.Getenv("INPUT_POST_TITLE")
url := os.Getenv("INPUT_POST_URL")
if (len(username) == 0 || len(password) == 0) {
fmt.Println("No supplied credentials. Provide `username` & `password`");
return 1
}
if (len(title) == 0 || len(url) == 0) {
fmt.Println("No supplied post. Provide `title` & `url` to post");
return 1
}
client := hkn.NewClient()
cookie, err := client.Login(username, password)
if (err != nil) {
fmt.Println(err)
return 1
}
created, err := client.CreateStoryWithURL(title, url, cookie)
if (err != nil) {
fmt.Println(err)
return 1
} else if (created == false) {
fmt.Println("Unknown error posting to HN")
return 1
}
fmt.Println("Successfully submitted to HN")
return 0
}
func main() {
os.Exit(_main())
}