dae/component/outbound/dialer/annotation.go
2024-01-04 17:28:16 +08:00

42 lines
856 B
Go

/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (c) 2022-2024, daeuniverse Organization <dae@v2raya.org>
*/
package dialer
import (
"fmt"
"time"
"github.com/daeuniverse/dae/pkg/config_parser"
)
const (
AnnotationKey_AddLatency = "add_latency"
)
type Annotation struct {
AddLatency time.Duration
}
func NewAnnotation(annotation []*config_parser.Param) (*Annotation, error) {
var anno Annotation
for _, param := range annotation {
switch param.Key {
case AnnotationKey_AddLatency:
latency, err := time.ParseDuration(param.Val)
if err != nil {
return nil, fmt.Errorf("incorrect latency format: %w", err)
}
// Only the first setting is valid.
if anno.AddLatency == 0 {
anno.AddLatency = latency
}
default:
return nil, fmt.Errorf("unknown filter annotation: %v", param.Key)
}
}
return &anno, nil
}