"Fossies" - the Fresh Open Source Software Archive

Member "frp-0.36.2/pkg/util/version/version.go" (22 Mar 2021, 1742 Bytes) of package /linux/misc/frp-0.36.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Go source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "version.go": 0.36.1_vs_0.36.2.

    1 // Copyright 2016 fatedier, fatedier@gmail.com
    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 implied.
   12 // See the License for the specific language governing permissions and
   13 // limitations under the License.
   14 
   15 package version
   16 
   17 import (
   18     "strconv"
   19     "strings"
   20 )
   21 
   22 var version string = "0.36.2"
   23 
   24 func Full() string {
   25     return version
   26 }
   27 
   28 func getSubVersion(v string, position int) int64 {
   29     arr := strings.Split(v, ".")
   30     if len(arr) < 3 {
   31         return 0
   32     }
   33     res, _ := strconv.ParseInt(arr[position], 10, 64)
   34     return res
   35 }
   36 
   37 func Proto(v string) int64 {
   38     return getSubVersion(v, 0)
   39 }
   40 
   41 func Major(v string) int64 {
   42     return getSubVersion(v, 1)
   43 }
   44 
   45 func Minor(v string) int64 {
   46     return getSubVersion(v, 2)
   47 }
   48 
   49 // add every case there if server will not accept client's protocol and return false
   50 func Compat(client string) (ok bool, msg string) {
   51     if LessThan(client, "0.18.0") {
   52         return false, "Please upgrade your frpc version to at least 0.18.0"
   53     }
   54     return true, ""
   55 }
   56 
   57 func LessThan(client string, server string) bool {
   58     vc := Proto(client)
   59     vs := Proto(server)
   60     if vc > vs {
   61         return false
   62     } else if vc < vs {
   63         return true
   64     }
   65 
   66     vc = Major(client)
   67     vs = Major(server)
   68     if vc > vs {
   69         return false
   70     } else if vc < vs {
   71         return true
   72     }
   73 
   74     vc = Minor(client)
   75     vs = Minor(server)
   76     if vc > vs {
   77         return false
   78     } else if vc < vs {
   79         return true
   80     }
   81     return false
   82 }