-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package infrastructure | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
) | ||
|
||
type FileHandler struct {} | ||
|
||
func NewFileHandler() *FileHandler { | ||
return &FileHandler{} | ||
} | ||
|
||
func (handler *FileHandler) Read(filepath string) (string, error) { | ||
bytes, err := ioutil.ReadFile(filepath) | ||
if err != nil { | ||
return "", err | ||
} | ||
return string(bytes), nil | ||
} | ||
|
||
func (handler *FileHandler) Write(filepath string, text string) error { | ||
fp, err := os.OpenFile(filepath, os.O_RDWR|os.O_CREATE, 0644) | ||
if err != nil { | ||
return err | ||
} | ||
defer fp.Close() | ||
fp.WriteString(text) | ||
return nil | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package infrastructure | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"crypto/tls" | ||
"io/ioutil" | ||
) | ||
|
||
type GrowiHandler struct { | ||
endpoint string | ||
token string | ||
} | ||
|
||
func NewGrowiHandler(endpoint string, token string) *GrowiHandler { | ||
return &GrowiHandler { | ||
endpoint, | ||
token, | ||
} | ||
} | ||
|
||
func (handler *GrowiHandler) GetPage(path string) (string, error) { | ||
url := handler.endpoint + "pages.get" | ||
req, _ := http.NewRequest("GET", url, nil) | ||
req.Header.Set("Authorization", "Bearer " + handler.token) | ||
|
||
params := req.URL.Query(); | ||
params.Add("access_token", handler.token) | ||
params.Add("path", path) | ||
req.URL.RawQuery = params.Encode() | ||
|
||
fmt.Println(req.URL.String()) | ||
client := &http.Client{ | ||
Transport: &http.Transport { | ||
TLSClientConfig: &tls.Config{ InsecureSkipVerify: true }, | ||
}, | ||
} | ||
resp, err := client.Do(req) | ||
if err != nil { | ||
return "", err | ||
} | ||
defer resp.Body.Close() | ||
fmt.Println(resp.StatusCode) | ||
byteArray, _ := ioutil.ReadAll(resp.Body) | ||
fmt.Println(string(byteArray)) | ||
return "", nil | ||
} |