package main import ( "encoding/json" "fmt" "log" "net/http" "io/ioutil" "gopkg.in/yaml.v3" ) type ApiConfig struct { Version string `yaml:"version"` Project string `yaml:"project"` Endpoints []Endpoint `yaml:"endpoints"` } type Endpoint struct { Path string `yaml:"path"` Method string `yaml:"method"` CobolSource string `yaml:"cobol_source"` Procedure string `yaml:"procedure"` Arguments []Argument `yaml:"arguments"` ResponseCopybook string `yaml:"response_copybook"` } type Argument struct { Name string `yaml:"name"` Target string `yaml:"target"` Type string `yaml:"type"` Source string `yaml:"source"` } func readConf(filename string) (*ApiConfig, error) { buf, err := ioutil.ReadFile(filename) if err != nil { return nil, err } c := &ApiConfig{} err = yaml.Unmarshal(buf, c) if err != nil { return nil, fmt.Errorf("in file %q: %w", filename, err) } return c, err } func projectHandler(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodGet { http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) return } w.Header().Set("Content-Type", "application/json") api, err := readConf("api.yaml") if err != nil { log.Fatal(err) } response := map[string]string{"project": api.Project} json.NewEncoder(w).Encode(response) } func main() { http.HandleFunc("/project", projectHandler) port := ":8080" fmt.Printf("Server starting on port %s...\n", port) if err := http.ListenAndServe(port, nil); err != nil { log.Fatalf("Server failed to start: %v", err) } }