Source file src/go/version/example_test.go
1 // Copyright 2026 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package version_test 6 7 import ( 8 "fmt" 9 "go/version" 10 "slices" 11 ) 12 13 func ExampleCompare() { 14 versions := []string{ 15 "go1.21.0", 16 "go1.9", 17 "go1.21", 18 "go1.21rc1", 19 "go1.10", 20 } 21 22 slices.SortFunc(versions, version.Compare) 23 24 fmt.Println(versions) 25 26 // Output: 27 // [go1.9 go1.10 go1.21 go1.21rc1 go1.21.0] 28 } 29