File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ func main() {
53
53
filetype := flag .String ("t" , "" , "Sets the file extension and syntax type." )
54
54
privateFlag := flag .Bool ("p" , false , "Indicates whether the gist is private." )
55
55
desc := flag .String ("d" , "" , "A description of the gist." )
56
- shortenFlag := flag .Bool ("- s" , false , "Shorten the gist URL using git.io." )
56
+ shortenFlag := flag .Bool ("s" , false , "Shorten the gist URL using git.io." )
57
57
uid := flag .String ("u" , "" , "Update an existing gist. Takes ID as an argument." )
58
58
anonymousFlag := flag .Bool ("a" , false , "Create an anonymous gist." )
59
59
copyFlag := flag .Bool ("c" , false , "Copy the resulting URL to the clipboard." )
Original file line number Diff line number Diff line change @@ -4,9 +4,13 @@ import (
4
4
"encoding/json"
5
5
"errors"
6
6
"fmt"
7
+ "net/http"
8
+ neturl "net/url"
7
9
"strings"
8
10
)
9
11
12
+ const GitIOURL = "http://git.io"
13
+
10
14
func GistParseError (body []byte ) error {
11
15
var err map [string ]json.RawMessage
12
16
if err := json .Unmarshal (body , & err ); err != nil {
@@ -32,5 +36,15 @@ func GistParseError(body []byte) error {
32
36
}
33
37
34
38
func Shorten (url string ) (string , error ) {
35
- return "" , nil
39
+ resp , err := http .PostForm (GitIOURL , neturl.Values {"url" : {url }})
40
+ if err != nil {
41
+ return "" , err
42
+ }
43
+ defer resp .Body .Close ()
44
+
45
+ if resp .StatusCode == 201 {
46
+ url = resp .Header .Get ("Location" )
47
+ }
48
+
49
+ return url , nil
36
50
}
You can’t perform that action at this time.
0 commit comments