Skip to content

Commit 0fd8b9f

Browse files
author
ynn
committed
Refactored.
1 parent 5b9b17f commit 0fd8b9f

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

coefont/coefont.go

+2-9
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ type Common struct {
2828

2929
func APICall(req Request, common Common, resultChannel chan<- string) {
3030

31+
defer close(resultChannel)
32+
3133
var requestBody, err = json.Marshal(req)
3234
if err != nil {
3335
log.Printf("Failed to jsonalize the request body: %v\n", err)
34-
resultChannel <- ""
3536
return
3637
}
3738

@@ -46,7 +47,6 @@ func APICall(req Request, common Common, resultChannel chan<- string) {
4647
request, err := http.NewRequest(http.MethodPost, common.URL, bytes.NewReader(requestBody))
4748
if err != nil {
4849
log.Printf("Failed to create a first POST request: %v\n", err)
49-
resultChannel <- ""
5050
return
5151
}
5252
request.Header.Add("Content-Type", "application/json")
@@ -66,15 +66,13 @@ func APICall(req Request, common Common, resultChannel chan<- string) {
6666
response, err := client.Do(request)
6767
if err != nil {
6868
log.Printf("Failed to send a first POST request: %v\n", err)
69-
resultChannel <- ""
7069
return
7170
}
7271
defer response.Body.Close()
7372
if response.StatusCode != http.StatusFound {
7473
log.Printf("The response isn't 302 Found.\n")
7574
// b, _ := io.ReadAll(response.Body)
7675
// log.Println(string(b))
77-
resultChannel <- ""
7876
return
7977
}
8078

@@ -83,37 +81,32 @@ func APICall(req Request, common Common, resultChannel chan<- string) {
8381
request, err = http.NewRequest(http.MethodGet, redirectURL /* body = */, nil)
8482
if err != nil {
8583
log.Printf("Failed to create a second GET request: %v\n", err)
86-
resultChannel <- ""
8784
return
8885
}
8986
response, err = client.Do(request)
9087
if err != nil {
9188
log.Printf("Failed to send a second GET request: %v\n", err)
92-
resultChannel <- ""
9389
return
9490
}
9591
defer response.Body.Close()
9692

9793
content, err := io.ReadAll(response.Body)
9894
if err != nil {
9995
log.Printf("Failed to read the request body of a second GET request: %v\n", err)
100-
resultChannel <- ""
10196
return
10297
}
10398

10499
var filename = fmt.Sprintf("%v/%v_%v.wav", common.OutputDir, currentTime, req.Text)
105100
file, err := os.Create(filename)
106101
if err != nil {
107102
log.Printf("Failed to create the file [ %v ]: %v\n", filename, err)
108-
resultChannel <- ""
109103
return
110104
}
111105
defer file.Close()
112106

113107
_, err = file.Write(content)
114108
if err != nil {
115109
log.Printf("Failed to write to the file [ %v ]: %v\n", filename, err)
116-
resultChannel <- ""
117110
return
118111
}
119112

lint.sh

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
set -x
44

5+
find . -name '*.out' -delete &&
56
go fmt ./... &&
67
go vet ./... &&
78
golint ./... | grep --color=never -v -e 'exported type .* should have comment or be unexported' -e 'exported function .* should have comment or be unexported'

0 commit comments

Comments
 (0)