Skip to content

Commit

Permalink
add CloudRun
Browse files Browse the repository at this point in the history
  • Loading branch information
fmhr committed Sep 21, 2023
1 parent 2e80794 commit a8542c1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
34 changes: 34 additions & 0 deletions cloudRun.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package fj

import (
"encoding/json"
"fmt"
"io"
"net/http"
)

func CloudRun(cnf *Config, seed int) (map[string]float64, error) {
return googleCloudRun(cnf, seed)
}

func googleCloudRun(cnf *Config, seed int) (map[string]float64, error) {
url := fmt.Sprintf("%s?seed=%d", cnf.CloudURL, seed)

resp, err := http.Get(url)
if err != nil {
return nil, fmt.Errorf("error making GET request to %s: %v", url, err)
}
defer resp.Body.Close()

body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("error reading response body: %v", err)
}

var data map[string]float64
if err := json.Unmarshal(body, &data); err != nil {
return nil, fmt.Errorf("error parsing response body: %v", err)
}

return data, nil
}
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Config struct {
InfilePath string `toml:"InfilePath"`
OutfilePath string `toml:"OutfilePath"`
Jobs int `toml:"Jobs"`
CloudURL string `toml:"http://localhost:8080"`
}

func GenerateConfig() {
Expand Down
2 changes: 1 addition & 1 deletion run.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

// Run は指定された設定とシードに基づいてコマンドを実行する
func Run(cnf *Config, seed int) ([]byte, error) {
inputfile := fmt.Sprintf("%s%04d.txt", cnf.InfilePath, seed)
inputfile := fmt.Sprintf("%04d.txt", seed)
if _, err := os.Stat(inputfile); err != nil {
return []byte{}, fmt.Errorf("input file [%s] does not exist", inputfile)
}
Expand Down

0 comments on commit a8542c1

Please sign in to comment.