mirror of
https://github.com/zu1k/nali.git
synced 2025-01-23 21:59:02 +08:00
no use syscall
This commit is contained in:
parent
4afb25d084
commit
a51fbc8442
@ -1,22 +1,20 @@
|
|||||||
// +build windows
|
|
||||||
|
|
||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"syscall"
|
"runtime"
|
||||||
|
|
||||||
"golang.org/x/text/encoding/simplifiedchinese"
|
"golang.org/x/text/encoding/simplifiedchinese"
|
||||||
"golang.org/x/text/transform"
|
"golang.org/x/text/transform"
|
||||||
)
|
)
|
||||||
|
|
||||||
var pipeline = false
|
var needTransform = false
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
ftype, _ := syscall.GetFileType(syscall.Handle(os.Stdin.Fd()))
|
stat, _ := os.Stdin.Stat()
|
||||||
pipeline = ftype == 3
|
needTransform = ((stat.Mode() & os.ModeNamedPipe) != 0) && runtime.GOOS == "windows"
|
||||||
}
|
}
|
||||||
|
|
||||||
func Root(args []string) {
|
func Root(args []string) {
|
||||||
@ -24,7 +22,7 @@ func Root(args []string) {
|
|||||||
stdin := bufio.NewScanner(os.Stdin)
|
stdin := bufio.NewScanner(os.Stdin)
|
||||||
for stdin.Scan() {
|
for stdin.Scan() {
|
||||||
line := stdin.Text()
|
line := stdin.Text()
|
||||||
if pipeline {
|
if needTransform {
|
||||||
line, _, _ = transform.String(simplifiedchinese.GBK.NewDecoder(), line)
|
line, _, _ = transform.String(simplifiedchinese.GBK.NewDecoder(), line)
|
||||||
}
|
}
|
||||||
if line == "quit" || line == "exit" {
|
if line == "quit" || line == "exit" {
|
||||||
@ -42,7 +40,7 @@ func CDN(args []string) {
|
|||||||
stdin := bufio.NewScanner(os.Stdin)
|
stdin := bufio.NewScanner(os.Stdin)
|
||||||
for stdin.Scan() {
|
for stdin.Scan() {
|
||||||
line := stdin.Text()
|
line := stdin.Text()
|
||||||
if pipeline {
|
if needTransform {
|
||||||
line, _, _ = transform.String(simplifiedchinese.GBK.NewDecoder(), line)
|
line, _, _ = transform.String(simplifiedchinese.GBK.NewDecoder(), line)
|
||||||
}
|
}
|
||||||
if line == "quit" || line == "exit" {
|
if line == "quit" || line == "exit" {
|
@ -1,39 +0,0 @@
|
|||||||
// +build !windows
|
|
||||||
|
|
||||||
package app
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bufio"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Root(args []string) {
|
|
||||||
if len(args) == 0 {
|
|
||||||
stdin := bufio.NewScanner(os.Stdin)
|
|
||||||
for stdin.Scan() {
|
|
||||||
line := stdin.Text()
|
|
||||||
if line == "quit" || line == "exit" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
fmt.Printf("%s\n", ReplaceIPInString(ReplaceCDNInString(line)))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ParseIPs(args)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func CDN(args []string) {
|
|
||||||
if len(args) == 0 {
|
|
||||||
stdin := bufio.NewScanner(os.Stdin)
|
|
||||||
for stdin.Scan() {
|
|
||||||
line := stdin.Text()
|
|
||||||
if line == "quit" || line == "exit" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
fmt.Println(ReplaceCDNInString(line))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ParseCDNs(args)
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user