package main import ( "encoding/json" "fmt" "io" "os" ) type journalIdentity struct { OperationID string `json:"operation_id"` State string `json:"state"` } func readJournalOperation(path string) (journalIdentity, error) { file, err := os.Open(path) if err != nil { return journalIdentity{}, err } defer file.Close() var journal journalIdentity decoder := json.NewDecoder(io.LimitReader(file, 1024*1024)) if err := decoder.Decode(&journal); err != nil { return journalIdentity{}, err } var trailing any if err := decoder.Decode(&trailing); err != io.EOF { return journalIdentity{}, fmt.Errorf("journal must contain exactly one JSON value") } if journal.OperationID == "" || journal.State == "" { return journalIdentity{}, fmt.Errorf("journal identity or state is empty") } return journal, nil }