vitess.io/vitess@v0.16.2/go/mysql/collations/local.go (about) 1 //go:build !collations_library 2 3 /* 4 Copyright 2021 The Vitess Authors. 5 6 Licensed under the Apache License, Version 2.0 (the "License"); 7 you may not use this file except in compliance with the License. 8 You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12 Unless required by applicable law or agreed to in writing, software 13 distributed under the License is distributed on an "AS IS" BASIS, 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 See the License for the specific language governing permissions and 16 limitations under the License. 17 */ 18 19 package collations 20 21 import ( 22 "sync" 23 24 "vitess.io/vitess/go/internal/flag" 25 "vitess.io/vitess/go/vt/servenv" 26 ) 27 28 var defaultEnv *Environment 29 var defaultEnvInit sync.Once 30 31 // Local is the default collation Environment for Vitess. This depends 32 // on the value of the `mysql_server_version` flag passed to this Vitess process. 33 func Local() *Environment { 34 defaultEnvInit.Do(func() { 35 if !flag.Parsed() { 36 panic("collations.Local() called too early") 37 } 38 defaultEnv = NewEnvironment(servenv.MySQLServerVersion()) 39 }) 40 return defaultEnv 41 } 42 43 // Default returns the default collation for this Vitess process. 44 // This is based on the local collation environment, which is based on the user's configured 45 // MySQL version for this Vitess deployment. 46 func Default() ID { 47 return ID(Local().DefaultConnectionCharset()) 48 }