github.com/kiali/kiali@v1.84.0/tracing/jaeger/model/hash.go (about) 1 // Copyright (c) 2019 The Jaeger Authors. 2 // Copyright (c) 2017 Uber Technologies, Inc. 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 16 package model 17 18 import ( 19 "hash/fnv" 20 "io" 21 ) 22 23 // Hashable interface is for type that can participate in a hash computation 24 // by writing their data into io.Writer, which is usually an instance of hash.Hash. 25 type Hashable interface { 26 Hash(w io.Writer) error 27 } 28 29 // HashCode calculates a FNV-1a hash code for a Hashable object. 30 func HashCode(o Hashable) (uint64, error) { 31 h := fnv.New64a() 32 if err := o.Hash(h); err != nil { 33 return 0, err 34 } 35 return h.Sum64(), nil 36 }