github.com/vchain-us/vcn@v0.9.11-0.20210921212052-a2484d23c0b3/pkg/extractor/file/version.go (about)

     1  /*
     2   * Copyright (c) 2018-2020 vChain, Inc. All Rights Reserved.
     3   * This software is released under GPL3.
     4   * The full license information can be found under:
     5   * https://www.gnu.org/licenses/gpl-3.0.en.html
     6   *
     7   */
     8  
     9  package file
    10  
    11  import (
    12  	"regexp"
    13  
    14  	"github.com/blang/semver"
    15  )
    16  
    17  var verRe = regexp.MustCompile(`v[0-9]+\.[0-9]\.+[0-9]+`)
    18  
    19  func inferVer(filename string) string {
    20  	match := verRe.FindStringSubmatch(filename)
    21  	if len(match) > 0 {
    22  		v, err := semver.ParseTolerant(match[0])
    23  		if err == nil {
    24  			return v.String()
    25  		}
    26  	}
    27  	return ""
    28  }