mirror of
https://github.com/cedar2025/hysteria.git
synced 2025-08-06 09:21:51 +00:00
app
cmd
client.go
ping.go
root.go
server.go
utils.go
internal
misc
client.example.yaml
go.mod
go.sum
main.go
server.example.yaml
core
extras
.gitignore
README.md
go.work
go.work.sum
hyperbole.py
36 lines
783 B
Go
36 lines
783 B
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/apernet/hysteria/extras/utils"
|
|
)
|
|
|
|
// convBandwidth handles both string and int types for bandwidth.
|
|
// When using string, it will be parsed as a bandwidth string with units.
|
|
// When using int, it will be parsed as a raw bandwidth in bytes per second.
|
|
// It does NOT support float types.
|
|
func convBandwidth(bw interface{}) (uint64, error) {
|
|
switch bwT := bw.(type) {
|
|
case string:
|
|
return utils.StringToBps(bwT)
|
|
case int:
|
|
return uint64(bwT), nil
|
|
default:
|
|
return 0, fmt.Errorf("invalid type %T for bandwidth", bwT)
|
|
}
|
|
}
|
|
|
|
type configError struct {
|
|
Field string
|
|
Err error
|
|
}
|
|
|
|
func (e configError) Error() string {
|
|
return fmt.Sprintf("invalid config: %s: %s", e.Field, e.Err)
|
|
}
|
|
|
|
func (e configError) Unwrap() error {
|
|
return e.Err
|
|
}
|