github.com/osrg/gobgp/v3@v3.30.0/internal/pkg/version/version.go (about)

     1  // Copyright (C) 2018 Nippon Telegraph and Telephone Corporation.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //    http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
    12  // implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  
    16  package version
    17  
    18  import "fmt"
    19  
    20  const MAJOR uint = 3
    21  const MINOR uint = 30
    22  const PATCH uint = 0
    23  
    24  var COMMIT string = ""
    25  var IDENTIFIER string = ""
    26  var METADATA string = ""
    27  
    28  func Version() string {
    29  	var suffix string = ""
    30  	if len(IDENTIFIER) > 0 {
    31  		suffix = fmt.Sprintf("-%s", IDENTIFIER)
    32  	}
    33  
    34  	if len(COMMIT) > 0 || len(METADATA) > 0 {
    35  		suffix = suffix + "+"
    36  	}
    37  
    38  	if len(COMMIT) > 0 {
    39  		suffix = fmt.Sprintf("%s"+"commit.%s", suffix, COMMIT)
    40  
    41  	}
    42  
    43  	if len(METADATA) > 0 {
    44  		if len(COMMIT) > 0 {
    45  			suffix = suffix + "."
    46  		}
    47  		suffix = suffix + METADATA
    48  	}
    49  
    50  	return fmt.Sprintf("%d.%d.%d%s", MAJOR, MINOR, PATCH, suffix)
    51  }