Skip to content

Commit

Permalink
➕ add handler
Browse files Browse the repository at this point in the history
  • Loading branch information
x8xx committed Nov 28, 2020
1 parent 571a162 commit b636775
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
30 changes: 30 additions & 0 deletions infrastructure/file_handler.go
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
}
47 changes: 47 additions & 0 deletions infrastructure/growi_handler.go
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
}

0 comments on commit b636775

Please sign in to comment.