카테고리 보관물: 미분류

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.

쉘스크립트 IF문 – shell script if elif else

쉘스크립트(shell script)로도 If elif 를 사용할 수 있습니다.

가끔 쓰기 때문에 기억이 잘 나지 않아서 말이지요.

그리고 case 구문을 지원하기 때문에 여러 조건을 확인해야 하는 것도 가능하지만

case문은 가독성이 너무 떨어지기 때문에 거의 사용하지 않습니다.

어쨌든 shell script (bash 기준)에서 if, elif, else 구문은 이렇게 씁니다.

#!/bin/bash

a="1"
if [[ $a == "1" ]]; then
    echo "a is 1"
elif [[ $a == "2" ]]; then
    echo "a is 2"
elif [[ $a == "3" ]]; then
    echo "a is 3"
elif [[ $a == "4" ]]; then
    echo "a is 4"
else
    echo "a is not 1, 2, 3, or 4"
fi