golang实现版本号比较

写一下,好久没更新博客了。

import (
    "fmt"
    "strings"
    "testing"
    "time"
)

/**
*Created by 908204694@qq.com 
*/

//版本号大
const VersionBig = 1

//版本号小
const VersionSmall = 2

//版本号相等
const VersionEqual = 0

func Test_version(t *testing.T) {

    versionA := "1.2.3a"
    versionB := "1.2.3b"
    fmt.Println(compareStrVer(versionA, versionB))

    time.LoadLocation("Local")
    fmt.Println(time.Now())
}

func compareStrVer(verA, verB string) int {

    verStrArrA := spliteStrByNet(verA)
    verStrArrB := spliteStrByNet(verB)

    lenStrA := len(verStrArrA)
    lenStrB := len(verStrArrB)

    if lenStrA != lenStrB {
        panic("版本号格式不一致")

    }

    return compareArrStrVers(verStrArrA, verStrArrB)
}

点击查看原文


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以通过以下步骤在不联网的情况下安装Nginx: 1. 从其他联网的机器上下载Nginx的源码包(tar.gz格式)并复制到目标机器上。 2. 解压源码包,进入Nginx目录。 ```sh tar -xzvf nginx-x.x.x.tar.gz cd nginx-x.x.x ``` 3. 安装编译Nginx所需的依赖库。 ```sh sudo apt-get update sudo apt-get install build-essential libpcre3 libpcre3-dev zlib1g-dev libssl-dev ``` 4. 配置Nginx。 ```sh ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module ``` 这里指定了安装目录为`/usr/local/nginx`,同时开启了SSL、状态页和gzip静态压缩功能。 5. 编译并安装Nginx。 ```sh make sudo make install ``` 6. 验证Nginx是否安装成功。 ```sh /usr/local/nginx/sbin/nginx -v ``` 如果显示Nginx版本号,则说明安装成功。 7. 配置Nginx服务启动脚本。 ```sh sudo nano /etc/init.d/nginx ``` 将以下内容复制到文件中: ```sh #!/bin/bash # # nginx - this script starts and stops the nginx daemon # # chkconfig: - 85 15 # description: Nginx is an HTTP(S) server, HTTP(S) reverse \ # proxy and IMAP/POP3 proxy server # processname: nginx # config: /usr/local/nginx/conf/nginx.conf # pidfile: /usr/local/nginx/logs/nginx.pid # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 nginx="/usr/local/nginx/sbin/nginx" prog=$(basename $nginx) NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf" [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx lockfile=/var/lock/subsys/nginx start() { [ -x $nginx ] || exit 5 [ -f $NGINX_CONF_FILE ] || exit 6 echo -n $"Starting $prog: " daemon $nginx -c $NGINX_CONF_FILE retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval } stop() { echo -n $"Stopping $prog: " killproc $prog -QUIT retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval } restart() { configtest || return $? stop start } reload() { configtest || return $? echo -n $"Reloading $prog: " killproc $nginx -HUP RETVAL=$? echo } force_reload() { restart } configtest() { $nginx -t -c $NGINX_CONF_FILE } rh_status() { status $prog } rh_status_q() { rh_status >/dev/null 2>&1 } case "$1" in start) rh_status_q && exit 0 $1 ;; stop) rh_status_q || exit 0 $1 ;; restart|configtest) $1 ;; reload) rh_status_q || exit 7 $1 ;; force-reload) force_reload ;; status) rh_status ;; condrestart|try-restart) rh_status_q || exit 0 restart ;; *) echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" exit 2 esac ``` 然后执行以下命令保存并退出。 ``` Ctrl+X Y Enter ``` 8. 授予脚本执行权限。 ```sh sudo chmod +x /etc/init.d/nginx ``` 9. 启动Nginx服务。 ```sh sudo service nginx start ``` 验证Nginx是否已经启动: ```sh ps aux | grep nginx ``` 如果看到类似以下输出,则说明Nginx已经成功启动。 ```sh root 1234 0.0 0.2 12345 6789 ? Ss 12:34 0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf nginx 5678 0.0 0.5 23456 9876 ? S 12:35 0:00 nginx: worker process nginx 5679 0.0 0.5 23456 9876 ? S 12:35 0:00 nginx: worker process ``` 现在,您已经成功在不联网的情况下安装了Nginx。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值