Добавил изменения конфига
This commit is contained in:
parent
b6866f8540
commit
4c2f052d70
5 changed files with 223 additions and 62 deletions
52
supporter/supporter.go
Normal file
52
supporter/supporter.go
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
package supporter
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"miku/users"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func MapToStruct(toStructMap map[string]any) (users.VLESSUsers, error) {
|
||||
var vlessUsers users.VLESSUsers
|
||||
inbounds, ok := toStructMap["inbounds"].([]any)
|
||||
if !ok || len(inbounds) == 0 {
|
||||
return nil, errors.New("нет inbounds")
|
||||
}
|
||||
firstInbound, ok := inbounds[0].(map[string]any)
|
||||
if !ok || len(firstInbound) == 0 {
|
||||
return nil, errors.New("неизвестный формат inbound")
|
||||
}
|
||||
usedMap, ok := firstInbound["users"].([]any)
|
||||
if !ok || len(usedMap) == 0 {
|
||||
return nil, errors.New("неизвестный формат пользователей")
|
||||
}
|
||||
for _, curretMap := range usedMap {
|
||||
userMap := curretMap.(map[string]any)
|
||||
vlessUsers = append(vlessUsers, struct {
|
||||
Name string "json:\"name\""
|
||||
UUID uuid.UUID "json:\"uuid\""
|
||||
}{
|
||||
Name: userMap["name"].(string),
|
||||
UUID: uuid.MustParse(userMap["uuid"].(string)),
|
||||
})
|
||||
}
|
||||
return vlessUsers, nil
|
||||
}
|
||||
|
||||
func StructToConfig(vlessUsers users.VLESSUsers, configMap map[string]any) (map[string]any, error) {
|
||||
var toInterface []map[string]any
|
||||
newConfigMap := configMap
|
||||
structJson, err := json.Marshal(vlessUsers)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = json.Unmarshal(structJson, &toInterface)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
newConfigMap["inbounds"].([]any)[0].(map[string]any)["users"] = toInterface
|
||||
return newConfigMap, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue