{"modulePath":"github.com/lsongdev/ohmyserver","version":"v0.0.0-20261122084236-b256af617454","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package api\n\nPackage api manages saved SSH hosts and opens terminals on them, as a JSON API with relative routes plus a WebSocket terminal.\n\n## Constants\n\n```go\nconst (\n\tStatusConnectFailed  websocket.StatusCode = 4000 // reason: the error\n\tStatusHostKeyChanged websocket.StatusCode = 4001 // forget the pinned key to continue\n)\n```\nClose codes of the terminal socket beyond the standard ones, so the UI can offer the right next step.\n\n## Types\n\n```go\ntype ConnectError struct{ Err error }\n```\nConnectError wraps a failure to reach or authenticate to a host.\n\n```go\nfunc (e *ConnectError) Error() string\n```\n\n```go\nfunc (e *ConnectError) Unwrap() error\n```\n\n```go\ntype Input struct {\n\tName        string `json:\"name\"`\n\tAddress     string `json:\"address\"`\n\tPort        int    `json:\"port\"`\n\tUser        string `json:\"user\"`\n\tAuth        string `json:\"auth\"`\n\tPassword    string `json:\"password\"`\n\tPrivateKey  string `json:\"private_key\"`\n\tPassphrase  string `json:\"passphrase\"`\n\tDescription string `json:\"description\"`\n}\n```\nInput creates or updates a host. On update, empty secrets keep the stored ones.\n\n```go\ntype Service struct {\n\t// contains filtered or unexported fields\n}\n```\nService manages hosts.\n\n```go\nfunc NewService(ctx context.Context, st *store.SQLite, log *slog.Logger) (*Service, error)\n```\nNewService returns the service, generating the panel key on first use.\n\n```go\nfunc (s *Service) Connect(ctx context.Context, id int64) (*hosts.Conn, error)\n```\nConnect opens an authenticated connection to a stored host, pinning its key on first use.\n\n```go\nfunc (s *Service) Create(ctx context.Context, in Input) (hosts.View, error)\n```\nCreate saves a new host.\n\n```go\nfunc (s *Service) Delete(ctx context.Context, id int64) error\n```\nDelete removes a host.\n\n```go\nfunc (s *Service) ForgetHostKey(ctx context.Context, id int64) error\n```\nForgetHostKey clears the pinned key, e.g. after a server was reinstalled.\n\n```go\nfunc (s *Service) Get(ctx context.Context, id int64) (hosts.View, error)\n```\nGet returns one host.\n\n```go\nfunc (s *Service) Handler() http.Handler\n```\nHandler serves the API. Successful responses are {\"data\": ...}; failures are {\"error\": {\"code\": ..., \"message\": ...}} with a matching status.\n\n```go\nfunc (s *Service) List(ctx context.Context) ([]hosts.View, error)\n```\nList returns every host.\n\n```go\nfunc (s *Service) PublicKey() string\n```\nPublicKey returns the panel's public key in authorized\\_keys format: add it to ~/.ssh/authorized\\_keys on hosts that use the \"panel\" method.\n\n```go\nfunc (s *Service) Summary(ctx context.Context) (Summary, error)\n```\nSummary counts hosts and open terminals.\n\n```go\nfunc (s *Service) Test(ctx context.Context, id int64, in Input) (TestResult, error)\n```\nTest connects with in, merged into the stored host id when id \u003e 0 (its secrets and pinned key), without saving anything.\n\n```go\nfunc (s *Service) Update(ctx context.Context, id int64, in Input) (hosts.View, error)\n```\nUpdate changes a host. A new address or port forgets the pinned host key, since it belongs to the old server.\n\n```go\ntype Summary struct {\n\tHosts    int   `json:\"hosts\"`\n\tSessions int64 `json:\"sessions\"`\n}\n```\nSummary counts hosts and open terminals for an overview.\n\n```go\ntype TestResult struct {\n\tHostKeyType   string `json:\"host_key_type\"`\n\tHostKeySHA256 string `json:\"host_key_sha256\"`\n\tPinned        bool   `json:\"pinned\"` // the key was already pinned\n}\n```\nTestResult reports a successful test connection.\n\n","path":"github.com/lsongdev/ohmyserver/modules/ssh/api","name":"api","synopsis":"Package api manages saved SSH hosts and opens terminals on them, as a JSON API with relative routes plus a WebSocket terminal.","isRedistributable":true}
