声明且未使用

I can't find why below code gives compile error "alive declared and not used".

func ping(ip string)  {     
    var alive bool
    _, err := exec.Command("ping", "-n 1", "-w 1000", ip).Output()
    if err != nil {
        alive = false
    } else {
        alive = true
    }
}

The compile error you're seeing is exactly what is happening. That var alive bool is unused. You declare it and assign a value to it but you never do anything with it.

Here is a playground-friendly modification of your code that will run:

package main

import (
    "fmt"
    "strconv"
)

func main() {
    fmt.Println(isInt("Hello, playground")) // prints false
    fmt.Println(isInt("1234567890")) // prints true
}

func isInt(s string) bool {
    var alive bool
    _, err := strconv.Atoi(s) // simply to demonstrate an error case
    if err != nil {
        alive = false
    } else {
        alive = true
    }
    return alive    
}

Notice that I return alive. The function is useless and not something I would suggest in and of itself but it should help illustrate what is missing in your example.

Since it is a local variable, it will exit scope at the end of the function. alive is neither evaluated nor returned inside the function. Hence the compiler complains.

Those strange limitations in Golang Devs team heads are terribly annoying.

Why not to allow people to disable their limitations with options?

Answer is simple: they write the lang for themselves (for guugle), not for the community.

Fortunately, Go is OpenSource and even written in Go.

So, here is a simple patch removing the "declared and not used" or "declared but not used" errors raising:

diff --git a/src/cmd/compile/internal/gc/walk.go b/src/cmd/compile/internal/gc/walk.go
index 770210f..78c0cbc 100644
--- a/src/cmd/compile/internal/gc/walk.go
+++ b/src/cmd/compile/internal/gc/walk.go
@@ -49,10 +49,7 @@ func walk(fn *Node) {
                        if defn.Left.Name.Used() {
                                continue
                        }
-                       yyerrorl(defn.Left.Pos, "%v declared and not used", ln.Sym)
                        defn.Left.Name.SetUsed(true) // suppress repeats
-               } else {
-                       yyerrorl(ln.Pos, "%v declared and not used", ln.Sym)
                }
        }

diff --git a/src/go/types/stmt.go b/src/go/types/stmt.go
index abd9d05..8b15786 100644
--- a/src/go/types/stmt.go
+++ b/src/go/types/stmt.go
@@ -55,6 +55,7 @@ func (check *Checker) funcBody(decl *declInfo, name string, sig *Signature, body
 }

 func (check *Checker) usage(scope *Scope) {
+       return
        var unused []*Var
        for _, elem := range scope.elems {
                if v, _ := elem.(*Var); v != nil && !v.used {

(Actual for go1.12)

Unpack a fresh Golang into /usr/local/go and apply the patch.

Then compile:

export GOROOT_BOOTSTRAP=/usr/local/go2
cp -a /usr/local/go /usr/local/go2
cd /usr/local/go/src
sed -e 's#^bash run.bash.*##' -i all.bash
./all.bash
rm -rf /usr/local/go2
unset GOROOT_BOOTSTRAP

It's much faster to apply the patch once [per new version] than every time deal with every missed variable.