Drive MistServer
from Go.
A small, typed client for the MistServer controller API. Create streams, wire up pushes and restreams, and let the SDK handle the challenge-response login.
go get github.com/Allan-Nava/MistServer-go-sdk
// Add a stream and restream it whenever it goes live
_, err := client.PostStream(mist.PostStreamRequest{
AddStream: map[string]mist.AddStream{
"live": {Name: "live", Source: "push://"},
},
})
_, err = client.PostAutoPush(mist.PostAutoPushRequest{
PushAutoAdd: mist.PushAutoAdd{
Stream: "live",
Target: "rtmp://ingest.example.com/app/KEY",
},
})
Why
The controller API, without the plumbing
MistServer exposes everything through one JSON endpoint and a login handshake. This SDK turns that into Go methods with request and response types.
Auth handled
The challenge round-trip and hashed password are done for you, and reused for a minute so calls don't pay for a second request.
Typed payloads
Structs for streams, auto-pushes, push lists and server config, so the compiler catches a misspelt field before MistServer does.
Bring your own client
Pass in your own resty client and zap logger, so timeouts, TLS, retries and log format stay under your control.
Quickstart
From zero to a live restream
The controller API usually listens on :4242/api. Point the client at it with the admin credentials you set in MistServer.
- Install
go getthe module. Go 1.25 or newer. - ConfigurePass a resty client, a sugared zap logger, and the
With…options. - CallEvery method logs in on its own; you just send the request.
package main
import (
"fmt"
"log"
mist "github.com/Allan-Nava/MistServer-go-sdk/mist"
"github.com/go-resty/resty/v2"
"go.uber.org/zap"
)
func main() {
logger, _ := zap.NewProduction()
defer logger.Sync()
client := mist.NewService(
resty.New(),
logger.Sugar(),
mist.WithBaseURL("http://localhost:4242/api"),
mist.WithUsername("admin"),
mist.WithPassword("secret"),
)
pushes, err := client.PostPushList(mist.PostPushListRequest{PushList: true})
if err != nil {
log.Fatal(err)
}
fmt.Println(len(pushes.PushList), "active pushes")
}
API
Every documented API call
56 methods, one per MistServer API command, checked against the controller source where the docs disagree. PostRaw covers anything else. Field-level docs and a runnable example for every method are on pkg.go.dev; command semantics are in the MistServer API reference.
| Method | Command | What it does |
|---|---|---|
| Streams | ||
| Health() | authorize | Logs in; returns server config, configured streams and the recent log. |
| PostStream(req) | addstream | Creates or updates streams; an update replaces the stream's whole config. |
| PostStreams(req) | streams | Replaces the whole stream list; an empty map deletes every stream. |
| PostStreamRemove(req) | deletestream | Deletes a stream. |
| PostDeleteStreamSource(req) | deletestreamsource | Deletes streams and their source files. |
| PostNukeStream(req) | nuke_stream | Force-stops a stream and cleans up its memory. |
| PostNoUnconfiguredStreams() | no_unconfigured_streams | Nukes active streams that are not configured. |
| PostTagStream(req) | tag_stream | Adds stream tags. |
| PostUntagStream(req) | untag_stream | Removes stream tags. |
| PostStreamTags(req) | stream_tags | Returns stream tags; no names means all active streams. |
| Pushes | ||
| PostPushStart(req) | push_start | Starts a push now. |
| PostPushList(req) | push_list | Lists running pushes. |
| PostPushStop(req) | push_stop | Stops running pushes by ID. |
| PostAutoPush(req) | push_auto_add | Adds an auto-push rule. |
| PostAutoPushRemove(req) | push_auto_remove | Removes auto-push rules. |
| PostPushAutoList() | push_auto_list | Lists auto-push rules by ID. |
| PostPushSettings(req) | push_settings | Reads or changes auto-push restart settings. |
| Statistics & server info | ||
| PostActiveStreams(req) | active_streams | Active streams with the fields you ask for. |
| PostStatsStreams(req) | stats_streams | Streams with statistics in the last ~10 minutes. |
| PostClients(req) | clients | Connected clients at a point in time. |
| PostTotals(req) | totals | Aggregated statistics over a period. |
| PostProcList(req) | proc_list | Running stream processes. |
| PostCapabilities() | capabilities | Installed inputs/outputs, CPU, load and memory. |
| PostAPIEndpoint() | api_endpoint | The local TCP API URL. |
| PostBrowse(req) | browse | Lists a directory on the server. |
| Sessions | ||
| PostStopSessions(req) | stop_sessions | Disconnects sessions by stream and protocol. |
| PostStopSessID(req) | stop_sessid | Disconnects sessions by ID. |
| PostStopTag(req) | stop_tag | Disconnects sessions by session tag. |
| PostTagSessID(req) | tag_sessid | Tags sessions. |
| PostInvalidateSessions(req) | invalidate_sessions | Re-runs USER_NEW for a stream's sessions. |
| Configuration & control | ||
| PostConfig(req) | config | Changes core server settings. |
| PostAddProtocol(req) | addprotocol | Enables outputs. |
| PostDeleteProtocol(req) | deleteprotocol | Removes outputs that match exactly. |
| PostUpdateProtocol(req) | updateprotocol | Replaces an output configuration. |
| PostConfigBackup() | config_backup | Returns the full configuration. |
| PostConfigRestore(req) | config_restore | Replaces the full configuration. |
| PostSave() | save | Writes the configuration to disk now. |
| PostUISettings(req) | ui_settings | Stores or reads interface settings. |
| PostClearStatLogs() | clearstatlogs | Truncates the server log. |
| PostUpdate() | update | Cached update information. |
| PostAutoUpdate() | autoupdate | Starts a rolling update, if available. |
| PostLogout() | logout | Drops the login on the connection. |
| PostShutdown(req) | shutdown | Shuts the controller down (local connections only). |
| Access keys | ||
| PostStreamKeys(req) | streamkeys | Reads or replaces all stream keys. |
| PostStreamKeyAdd(req) | streamkey_add | Adds or re-points stream keys. |
| PostStreamKeyDel(req) | streamkey_del | Deletes stream keys. |
| PostJWKS(req) | jwks | Reads or replaces all JSON Web Keys. |
| PostAddJWKS(req) | addjwks | Adds JSON Web Keys. |
| PostDeleteJWKS(req) | deletejwks | Removes JSON Web Keys by kid or exact match. |
| Variables & external writers | ||
| PostVariableList() | variable_list | Lists custom variables. |
| PostVariableAdd(req) | variable_add | Adds or updates a custom variable. |
| PostVariableRemove(req) | variable_remove | Removes custom variables. |
| PostExternalWriterList() | external_writer_list | Lists external writers. |
| PostExternalWriterAdd(req) | external_writer_add | Adds an external writer. |
| PostExternalWriterRemove(req) | external_writer_remove | Removes an external writer. |
| Anything else | ||
| PostRaw(command) | any | Sends arbitrary members, e.g. several commands at once; returns the reply undecoded. |
Auth
Challenge-response, done once a minute
MistServer never receives the plain password. The first request fetches a challenge; the SDK answers with md5(md5(password) + challenge) and reuses that answer for the next 60 seconds, behind a mutex, so concurrent calls share it.
MistServer replies HTTP 200 even to a rejected login, so the SDK checks authorize.status on every reply. A stale challenge (it rolls over daily) is retried once; wrong credentials, or a server with no accounts, return mist.ErrUnauthorized.
MD5 is what the MistServer protocol specifies. Put the API behind TLS or a private network if it leaves the host.