태그 보관물: Go언어

Go언어 CPU 수 알아내기

Go언어에서 CPU 수를 알아내는 코드입니다.

// OS, 아키텍쳐, CPU수, 고루틴 수를 출력한다.
package main

import (
	"fmt"
	"runtime"
)

func main() {
	fmt.Println("OS\t\t", runtime.GOOS)
	fmt.Println("ARCH\t\t", runtime.GOARCH)
	fmt.Println("CPU\t\t", runtime.NumCPU())
	fmt.Println("Goroutines\t", runtime.NumGoroutine())
}

Go언어 파일 목록 읽기

특정 디렉토리에 있는 파일 목록을 읽어오는 코드입니다.

요점

ioutil.ReadDir 함수를 사용하면 됩니다.

package main

import (
	"fmt"
	"io/ioutil"
	"log"
)

func main() {
	files, err := ioutil.ReadDir("/tmp/")
	if err != nil {
		log.Fatal(err)
	}

	for _, file := range files {
		fmt.Println(file.Name(), file.IsDir())
	}
}

How to retrieve a list of files from a particular directory.

Use “iotuil.ReadDir”

Go언어 csv.gz 읽기

csv파일은 gzip 압축이 되는 경우가 많습니다.

압축을 따로 풀지않고 gz 압축된 csv 파일을 직접 처리하는 것이 더 편할때가 많아졌습니다.

Go언어에서 gzip으로 압축된 csv 파일을 읽는 방법입니다.

package main

import (
	"compress/gzip"
	"encoding/csv"
	"fmt"
	"log"
	"os"
)

func main() {
	file, err := os.Open("data.csv.gz")

	if err != nil {
		log.Fatal(err)
	}

	defer file.Close()

	gzipReader, err := gzip.NewReader(file)

	if err != nil {
		log.Fatal(err)
	}

	defer gzipReader.Close()

	csvReader := csv.NewReader(gzipReader)
	record, err := csvReader.Read()

	if err != nil {
		log.Fatal(err)
	}

	for _, v := range record {
		fmt.Println(v)
	}
}

윈도우에서 Go언어 개발할 때 Avast 경고메세지 없애기

윈도우에서 Go언어로 개발할 때 Avast를 백신으로 사용하고 있다면 잦은 실행파일을 빌드할 때 마다 검사 경고가뜹니다.

디버깅이나 실행버튼을 누를때마다 이런 일이 일어나기 때문에 굉장히 귀찮고 소리도 무척 거슬립니다.

해결책

Avast의 CyberCapture 기능을 비할성화하면 이 문제가 사라집니다.

주의점

물론 보안상 조금 더 위험해집니다.

작업이 끝나면 원래대로 설정을 바꿔 놓을 수 있습니다.

스크린샷

When developing a Golang application in Windows, how to disable the alert message.

If you develop an application with Golang in the environment which use Avast antivirus for Antivirus solution then you may frequently see alert message from Avast antivirus. for the purpose of removing the alert message.

Solution. You can disable the CyberCapture in your Avast configuration.