|
| 1 | +// SPDX-License-Identifier: PMPL-1.0-or-later |
| 2 | +// Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) |
| 3 | +// |
| 4 | +// V-echidna — V-lang connector for echidna API. |
| 5 | +// Groove-aware: supports snap-on/snap-off discovery. |
| 6 | + |
| 7 | +module v_echidna |
| 8 | + |
| 9 | +import net.http |
| 10 | +import json |
| 11 | + |
| 12 | +// Configuration |
| 13 | +pub struct Config { |
| 14 | +pub mut: |
| 15 | + base_url string = 'http://localhost:8081' |
| 16 | +} |
| 17 | + |
| 18 | +pub fn new_config(port int) Config { |
| 19 | + return Config{ base_url: 'http://localhost:${port}' } |
| 20 | +} |
| 21 | + |
| 22 | +// Client |
| 23 | +pub struct Client { |
| 24 | + config Config |
| 25 | +} |
| 26 | + |
| 27 | +pub fn new_client(config Config) &Client { |
| 28 | + return &Client{ config: config } |
| 29 | +} |
| 30 | + |
| 31 | +pub fn new_default() &Client { |
| 32 | + return new_client(Config{}) |
| 33 | +} |
| 34 | + |
| 35 | +// Health check |
| 36 | +pub fn (c &Client) health() !string { |
| 37 | + resp := http.get('${c.config.base_url}/health') or { |
| 38 | + return error('echidna unreachable: ${err}') |
| 39 | + } |
| 40 | + if resp.status_code != 200 { |
| 41 | + return error('echidna unhealthy: HTTP ${resp.status_code}') |
| 42 | + } |
| 43 | + return resp.body |
| 44 | +} |
| 45 | + |
| 46 | +// Groove discovery — scan known ports for echidna |
| 47 | +pub fn discover(ports ...int) ?&Client { |
| 48 | + scan_ports := if ports.len > 0 { ports } else { [8081] } |
| 49 | + for port in scan_ports { |
| 50 | + client := new_client(new_config(port)) |
| 51 | + if _ := client.health() { |
| 52 | + return client |
| 53 | + } |
| 54 | + } |
| 55 | + return none |
| 56 | +} |
| 57 | + |
| 58 | +// Groove manifest |
| 59 | +pub struct GrooveManifest { |
| 60 | +pub: |
| 61 | + service string = 'echidna' |
| 62 | + version string = '0.1.0' |
| 63 | + api_types []string = ['rest', 'grpc', 'graphql'] |
| 64 | + endpoints []string = ['health', 'prove', 'verify', 'backends', 'explain'] |
| 65 | +} |
| 66 | + |
| 67 | +pub fn groove_manifest() GrooveManifest { |
| 68 | + return GrooveManifest{} |
| 69 | +} |
0 commit comments