인자 체크 부분

2019. 2. 7. 17:36

cybertramp LANG/golang

처음 커맨드라인을 통해 인자를 받을 때 해당 인자를 입력 안하는 경우 오류에 대한 출력이 필요하다. 그런 경우 사용하는 소스코드이다.



1
2
3
4
5
6
7
8
9
func main(){
    if len(os.Args) > 1 { 
        arg := os.Args[1]
        fileName := Keygen(arg)
        fmt.Printf("Pri(%s.key) and Pub(%s.pubkey) key created.\n",fileName,fileName)
    } else{
        fmt.Printf("Please input keyfile name parameter.\n")
    }   
}
cs


해당 소스코드는 인자의 개수를 체크하여 인자가 입력되었는지 확인한다. 이상한 값이 들어가도 실행될 것이다.