github.com/v2fly/v2ray-core/v5@v5.16.2-0.20240507031116-8191faa6e095/infra/conf/merge/priority.go (about) 1 // Copyright 2020 Jebbs. All rights reserved. 2 // Use of this source code is governed by MIT 3 // license that can be found in the LICENSE file. 4 5 package merge 6 7 import "sort" 8 9 func getPriority(v interface{}) float64 { 10 var m map[string]interface{} 11 var ok bool 12 if m, ok = v.(map[string]interface{}); !ok { 13 return 0 14 } 15 if i, ok := m[priorityKey]; ok { 16 if p, ok := i.(float64); ok { 17 return p 18 } 19 } 20 return 0 21 } 22 23 // sortByPriority sort slice by priority fields of their elements 24 func sortByPriority(slice []interface{}) { 25 sort.Slice( 26 slice, 27 func(i, j int) bool { 28 return getPriority(slice[i]) < getPriority(slice[j]) 29 }, 30 ) 31 }