分类 golang 下的文章

编译

set GOOS=linux

set GOARCH=amd64

go build -o "packageName"

发布

上传到服务器相关目录

chmod 777 main ------------修改权限

nohup ./main >log.txt --------后台运行程序

查看

查看运行进程pid: ps aux |grep main (main为名称)

服务器执行后台运行代码: nohup ./main &

关闭运行代码:kill -2 7159pid

ps -ef 可以查看所有进程

kill -pid 结束进程

比方说我通过查看进程发现上面运行的jar包的pid是21550,就可以这样结束它:

kill 21550

package tools

import (
    "math"
)

// WGS84坐标系:即地球坐标系,国际上通用的坐标系。
// GCJ02坐标系:即火星坐标系,WGS84坐标系经加密后的坐标系。Google Maps,高德在用。
// BD09坐标系:即百度坐标系,GCJ02坐标系经加密后的坐标系。

const (
    X_PI   = math.Pi * 3000.0 / 180.0
    OFFSET = 0.00669342162296594323
    AXIS   = 6378245.0
)

//BD09toGCJ02 百度坐标系->火星坐标系
func BD09toGCJ02(lon, lat float64) (float64, float64) {
    x := lon - 0.0065
    y := lat - 0.006

    z := math.Sqrt(x*x+y*y) - 0.00002*math.Sin(y*X_PI)
    theta := math.Atan2(y, x) - 0.000003*math.Cos(x*X_PI)

    gLon := z * math.Cos(theta)
    gLat := z * math.Sin(theta)

    return gLon, gLat
}

//GCJ02toBD09 火星坐标系->百度坐标系
func GCJ02toBD09(lon, lat float64) (float64, float64) {
    z := math.Sqrt(lon*lon+lat*lat) + 0.00002*math.Sin(lat*X_PI)
    theta := math.Atan2(lat, lon) + 0.000003*math.Cos(lon*X_PI)

    bdLon := z*math.Cos(theta) + 0.0065
    bdLat := z*math.Sin(theta) + 0.006

    return bdLon, bdLat
}

//WGS84toGCJ02 WGS84坐标系->火星坐标系
func WGS84toGCJ02(lon, lat float64) (float64, float64) {
    if isOutOFChina(lon, lat) {
        return lon, lat
    }

    mgLon, mgLat := delta(lon, lat)

    return mgLon, mgLat
}

//GCJ02toWGS84 火星坐标系->WGS84坐标系
func GCJ02toWGS84(lon, lat float64) (float64, float64) {
    if isOutOFChina(lon, lat) {
        return lon, lat
    }

    mgLon, mgLat := delta(lon, lat)

    return lon*2 - mgLon, lat*2 - mgLat
}

//BD09toWGS84 百度坐标系->WGS84坐标系
func BD09toWGS84(lon, lat float64) (float64, float64) {
    lon, lat = BD09toGCJ02(lon, lat)
    return GCJ02toWGS84(lon, lat)
}

//WGS84toBD09 WGS84坐标系->百度坐标系
func WGS84toBD09(lon, lat float64) (float64, float64) {
    lon, lat = WGS84toGCJ02(lon, lat)
    return GCJ02toBD09(lon, lat)
}

func delta(lon, lat float64) (float64, float64) {
    dlat := transformlat(lon-105.0, lat-35.0)
    dlon := transformlng(lon-105.0, lat-35.0)

    radlat := lat / 180.0 * math.Pi
    magic := math.Sin(radlat)
    magic = 1 - OFFSET*magic*magic
    sqrtmagic := math.Sqrt(magic)

    dlat = (dlat * 180.0) / ((AXIS * (1 - OFFSET)) / (magic * sqrtmagic) * math.Pi)
    dlon = (dlon * 180.0) / (AXIS / sqrtmagic * math.Cos(radlat) * math.Pi)

    mgLat := lat + dlat
    mgLon := lon + dlon

    return mgLon, mgLat
}

func transformlat(lon, lat float64) float64 {
    var ret = -100.0 + 2.0*lon + 3.0*lat + 0.2*lat*lat + 0.1*lon*lat + 0.2*math.Sqrt(math.Abs(lon))
    ret += (20.0*math.Sin(6.0*lon*math.Pi) + 20.0*math.Sin(2.0*lon*math.Pi)) * 2.0 / 3.0
    ret += (20.0*math.Sin(lat*math.Pi) + 40.0*math.Sin(lat/3.0*math.Pi)) * 2.0 / 3.0
    ret += (160.0*math.Sin(lat/12.0*math.Pi) + 320*math.Sin(lat*math.Pi/30.0)) * 2.0 / 3.0
    return ret
}

func transformlng(lon, lat float64) float64 {
    var ret = 300.0 + lon + 2.0*lat + 0.1*lon*lon + 0.1*lon*lat + 0.1*math.Sqrt(math.Abs(lon))
    ret += (20.0*math.Sin(6.0*lon*math.Pi) + 20.0*math.Sin(2.0*lon*math.Pi)) * 2.0 / 3.0
    ret += (20.0*math.Sin(lon*math.Pi) + 40.0*math.Sin(lon/3.0*math.Pi)) * 2.0 / 3.0
    ret += (150.0*math.Sin(lon/12.0*math.Pi) + 300.0*math.Sin(lon/30.0*math.Pi)) * 2.0 / 3.0
    return ret
}

func isOutOFChina(lon, lat float64) bool {
    return !(lon > 73.66 && lon < 135.05 && lat > 3.86 && lat < 53.55)
}

使用ma实现

func BuildCondition(where map[string]interface{}) (whereSql string,
    values []interface{}, err error) {
    for key, value := range where {
        conditionKey := strings.Split(key, " ")
        if len(conditionKey) > 2 {
            return "", nil, fmt.Errorf("" +
                "map构建的条件格式不对,类似于'age >'")
        }
        if whereSql != "" {
            whereSql += " AND "
        }
        switch len(conditionKey) {
        case 1:
            whereSql += fmt.Sprint(conditionKey[0], " = ?")
            values = append(values, value)
            break
        case 2:
            field := conditionKey[0]
            switch conditionKey[1] {
            case "=":
                whereSql += fmt.Sprint(field, " = ?")
                values = append(values, value)
                break
            case ">":
                whereSql += fmt.Sprint(field, " > ?")
                values = append(values, value)
                break
            case ">=":
                whereSql += fmt.Sprint(field, " >= ?")
                values = append(values, value)
                break
            case "<":
                whereSql += fmt.Sprint(field, " < ?")
                values = append(values, value)
                break
            case "<=":
                whereSql += fmt.Sprint(field, " <= ?")
                values = append(values, value)
                break
            case "in":
                whereSql += fmt.Sprint(field, " in (?)")
                values = append(values, value)
                break
            case "like":
                whereSql += fmt.Sprint(field, " like ?")
                values = append(values, value)
                break
            case "<>":
                whereSql += fmt.Sprint(field, " != ?")
                values = append(values, value)
                break
            case "!=":
                whereSql += fmt.Sprint(field, " != ?")
                values = append(values, value)
                break
            }
            break
        }
    }
    return
}

用法

conditionString, values, _ := tool.BuildCondition(map[string]interface{}{
        "itemNO":        "02WZ05133",
        "itemName like": "%22220",
        "id in":         []int{20, 19, 30},
        "num !=" : 20,
    })
var student model.Student
db.where(conditionString,values).Find(&student)