mirror of
				https://github.com/openimsdk/open-im-server.git
				synced 2025-11-04 11:22:10 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			62 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			62 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
// Copyright © 2023 OpenIM. All rights reserved.
 | 
						|
//
 | 
						|
// Licensed under the Apache License, Version 2.0 (the "License");
 | 
						|
// you may not use this file except in compliance with the License.
 | 
						|
// You may obtain a copy of the License at
 | 
						|
//
 | 
						|
//     http://www.apache.org/licenses/LICENSE-2.0
 | 
						|
//
 | 
						|
// Unless required by applicable law or agreed to in writing, software
 | 
						|
// distributed under the License is distributed on an "AS IS" BASIS,
 | 
						|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
						|
// See the License for the specific language governing permissions and
 | 
						|
// limitations under the License.
 | 
						|
 | 
						|
package oss
 | 
						|
 | 
						|
import (
 | 
						|
	"bytes"
 | 
						|
	"sort"
 | 
						|
)
 | 
						|
 | 
						|
// headerSorter defines the key-value structure for storing the sorted data in signHeader.
 | 
						|
type headerSorter struct {
 | 
						|
	Keys []string
 | 
						|
	Vals []string
 | 
						|
}
 | 
						|
 | 
						|
// newHeaderSorter is an additional function for function SignHeader.
 | 
						|
func newHeaderSorter(m map[string]string) *headerSorter {
 | 
						|
	hs := &headerSorter{
 | 
						|
		Keys: make([]string, 0, len(m)),
 | 
						|
		Vals: make([]string, 0, len(m)),
 | 
						|
	}
 | 
						|
 | 
						|
	for k, v := range m {
 | 
						|
		hs.Keys = append(hs.Keys, k)
 | 
						|
		hs.Vals = append(hs.Vals, v)
 | 
						|
	}
 | 
						|
	return hs
 | 
						|
}
 | 
						|
 | 
						|
// Sort is an additional function for function SignHeader.
 | 
						|
func (hs *headerSorter) Sort() {
 | 
						|
	sort.Sort(hs)
 | 
						|
}
 | 
						|
 | 
						|
// Len is an additional function for function SignHeader.
 | 
						|
func (hs *headerSorter) Len() int {
 | 
						|
	return len(hs.Vals)
 | 
						|
}
 | 
						|
 | 
						|
// Less is an additional function for function SignHeader.
 | 
						|
func (hs *headerSorter) Less(i, j int) bool {
 | 
						|
	return bytes.Compare([]byte(hs.Keys[i]), []byte(hs.Keys[j])) < 0
 | 
						|
}
 | 
						|
 | 
						|
// Swap is an additional function for function SignHeader.
 | 
						|
func (hs *headerSorter) Swap(i, j int) {
 | 
						|
	hs.Vals[i], hs.Vals[j] = hs.Vals[j], hs.Vals[i]
 | 
						|
	hs.Keys[i], hs.Keys[j] = hs.Keys[j], hs.Keys[i]
 | 
						|
}
 |