mirror of
https://github.com/renorris/openfsd
synced 2026-03-30 19:15:35 +08:00
Changes:
- Implement bootstrapping library for managing several concurrent internal services
- Refactor concurrency model for connections/logical clients and their associated I/O
- Refactor server context singleton
- Refactor error handling
- Most errors are now gracefully sent to the FSD client directly encoded as an $ER packet,
enhancing visibility and debugging
- Most errors are now rightfully treated as non-fatal
- Refactor package/dependency graph
- Refactor calling conventions/interfaces for many packages
- Refactor database package
- Refactor post office
Features:
- Add VATSIM-esque HTTP/JSON "data feed"
- Add ephemeral in-memory database option
- Add user management REST API
- Add improved web interface
- Add MySQL support (drop SQLite support)
27 lines
506 B
Go
27 lines
506 B
Go
package web
|
|
|
|
import (
|
|
"bytes"
|
|
"crypto/rand"
|
|
"encoding/hex"
|
|
"encoding/json"
|
|
"io"
|
|
"net/http"
|
|
)
|
|
|
|
func writeResponseError(w http.ResponseWriter, status int, resp any) {
|
|
w.WriteHeader(status)
|
|
if respBytes, err := json.Marshal(&resp); err == nil {
|
|
io.Copy(w, bytes.NewReader(respBytes))
|
|
}
|
|
}
|
|
|
|
func generateRandomPassword() (string, error) {
|
|
randBytes := make([]byte, 16)
|
|
if _, err := io.ReadFull(rand.Reader, randBytes); err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return hex.EncodeToString(randBytes), nil
|
|
}
|