chore: 暴露数据给前端

This commit is contained in:
adlyq
2022-05-17 16:47:21 +08:00
parent 0742f7db26
commit c4408612b3
5 changed files with 57 additions and 13 deletions

View File

@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"errors"
"github.com/gofrs/uuid"
"net"
"github.com/Dreamacro/clash/component/dialer"
@ -17,6 +18,7 @@ type Base struct {
tp C.AdapterType
udp bool
rmark int
id string
}
// Name implements C.ProxyAdapter
@ -24,6 +26,20 @@ func (b *Base) Name() string {
return b.name
}
// Id implements C.ProxyAdapter
func (b *Base) Id() string {
if b.id == "" {
id, err := uuid.NewV6()
if err != nil {
b.id = b.name
} else {
b.id = id.String()
}
}
return b.id
}
// Type implements C.ProxyAdapter
func (b *Base) Type() C.AdapterType {
return b.tp
@ -58,6 +74,7 @@ func (b *Base) SupportUDP() bool {
func (b *Base) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]string{
"type": b.Type().String(),
"id": b.Id(),
})
}