diff --git a/cloudRun.go b/cloudRun.go new file mode 100644 index 0000000..fd642cc --- /dev/null +++ b/cloudRun.go @@ -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 +} diff --git a/config.go b/config.go index 202fe98..bb6c34a 100644 --- a/config.go +++ b/config.go @@ -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() { diff --git a/run.go b/run.go index b38cdc1..32a29ad 100644 --- a/run.go +++ b/run.go @@ -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) }