inflearn logo
강의

Course

Instructor

GO Language Programming Core Basics Introduction Course, Easy and Quick to Complete

맵 예제 코드가 바이러스 검사에 걸려요

234

ljh01252430

1 asked

0

if _, ok := map12["kiwi"]; !ok { 
		fmt.Println("ex7 : kiwi is not exist!")
	}

visual studio code 1.86.2

에디션 Windows 10 Pro

버전 22H2

설치 날짜 ‎2023-‎10-‎09

OS 빌드 19045.4046

경험 Windows Feature Experience Pack 1000.19053.1000.0

 

이 버전에서 Map 기초 수업의 예제 코드가 바이러스 체크에 걸립니다..!

굉장히 흥미로운 현상인데, 같은 현상을 겪으시는 분이 있으신가요?

왜 그런 것일까요?

 

최대한 문제의 소스코드만 발라내보려고 했는데, 코드가 조금 덜어지면 디펜더에 안걸리네요... 신기하네요... 메모리 침범이라도 되나...

// 자료형 맵

package main

import "fmt"

func main() {
	// 맵 (Map)
	// 해시테이블, 딕셔너리(파이썬)
	// Key-Value로 자료 저장
	// 레퍼런스 타입 (참조값 전달)
	// 비교 연산자 사용 불가능 (참조 타입이므로)
	// 참조 타입으로는 Key에 사용 불가. Value로는 모든 타입 가능
	// make 함수 및 축약 (리터럴) 로 초기화 가능
	// 순서 없음

	// 예제 1
	var map1 map[string]int = make(map[string]int) // 정석
	var map2 = make(map[string]int)                // 자료형 생략
	map3 := make(map[string]int)                   // 리터럴형

	fmt.Println("ex1 : ", map1)
	fmt.Println("ex1 : ", map2)
	fmt.Println("ex1 : ", map3)
	fmt.Println()

	// 예제 2
	map4 := map[string]int{} // Json 형태
	map4["apple"] = 25
	map4["banana"] = 40
	map4["orange"] = 33
	map5 := map[string]int{
		"apple":  15,
		"banana": 40,
		"orange": 23,
	}
	map6 := make(map[string]int, 10)
	map6["apple"] = 25
	map6["banana"] = 40
	map6["orange"] = 33

	fmt.Println("ex2 : ", map4)
	fmt.Println("ex2 : ", map5)
	fmt.Println("ex2 : ", map6)
	fmt.Println("ex2 : ", map6["orange"])
	fmt.Println("ex2 : ", map6["apple"])

	// 예제 3 맵 조회 및 순회 (Iterator)
	map11 := map[string]string{
		"daum":   "http://daum.net",
		"naver":  "http://naver.com",
		"google": "http://google.com",
	}
	fmt.Println("ex3 : ", map11["google"])
	fmt.Println("ex3 : ", map11["daum"])
	fmt.Println()

	// 예제 4 순서 없으므로 랜덤
	for k, v := range map11 {
		fmt.Println("ex4 : ", k, v)
	}
	for k, v := range map11 { // 실행 중에도 순서 보장 X
		fmt.Println("ex4 : ", k, v)
	}
	for _, v := range map11 { // 스킵 가능
		fmt.Println("ex4 : ", v)
	}
	fmt.Println()

	// 예제 5 맵 값 변경 및 삭제
	fmt.Println("ex5 : ", map11)
	map11["home"] = "localhost" // 없을 때 추가
	fmt.Println("ex5 : ", map11)
	map11["home"] = "http://test.com" // 있을 때 수정
	fmt.Println("ex5 : ", map11)
	delete(map11, "home") // 삭제
	fmt.Println("ex5 : ", map11)

	// 예제 6 맵 조회할 경우의 주의 및 팁
	map12 := map[string]int{
		"apple":  15,
		"banana": 115,
		"orange": 1115,
		"lemon":  0,
	}
	value1 := map12["lemon"]
	value2 := map12["kiwi"]       // 존재 X. 변수형 기본값 int 0, string "", float 0.0
	value3, ok1 := map12["kiwi"]  // 키값 존재를 확인하기 위해 true, false
	value4, ok2 := map12["lemon"] // 두번째 리턴값으로 키값 존재 확인

	fmt.Println("ex6 : ", value1)
	fmt.Println("ex6 : ", value2)
	fmt.Println("ex6 : ", value3, ok1)
	fmt.Println("ex6 : ", value4, ok2)

	// 예제 7
	if value, ok := map12["kiwi"]; ok {
		fmt.Println("ex7 : ", value)
	} else {
		fmt.Println("ex7 : kiwi is not exist!")
	}
	if value, ok := map12["banana"]; ok {
		fmt.Println("ex7 : ", value)
	} else {
		fmt.Println("ex7 : banana is not exist!")
	}
	if _, ok := map12["kiwi"]; !ok { // _ 사용 가능, 키값 없을 때 예외 처리할 때 많이 사용
		fmt.Println("ex7 : kiwi is not exist!")
	} // ??? 윈도우 디펜더에서 바이러스 있어보인다고 막네요 ???
}

go

Answer 1

0

niceman

안녕하세요.

바이러스는 윈도우의 디펜더나 백신 강화 상태에서 따라서 스크립트를 악성웨어로 인식할 수가 있습니다.

해당 파일은 스킵 하시고 실행하시면 문제 없이 동작 가능합니다.

감사합니다.

고 인터페이스 관련

0

69

2

Join함수 사용이유가 궁금합니다

0

54

1

vscode 설정

0

126

2

arm64

0

202

2

undefined 에러 : UndeclaredImportedName

0

343

1

godoc 에러 관련

0

206

1

package is not in std 오류

0

986

1

for 반복문에서 break와 continue 차이점

0

224

1

후치연산 관련 질문입니다.

0

197

1

package관리에 질문이 있습니다.

0

282

1

go channel 에제에서 질문이 있습니다.

0

193

1

golang 질문

0

310

1

재귀 함수 관련하여 질문이 있습니다.

0

346

1

atom 서비스 종료 관련

0

403

1

vscode 환경설정 업데이트 부탁드립니다

1

404

2

waitGroup.Done을 지연 시키는 방식

0

449

1

첫 번째 예제 질문있습니다.

0

263

1

2개씩 체크가 되는 이유가 궁금합니다.

0

328

1

go 표준 코드 컨벤션이 있나요?

0

825

1

slice에서 make 궁금한 게 있습니다.

1

262

1

import 관리는 어떻게 하나요?

0

317

1

개발환경설정 질문드립니다.

0

486

1

이것도 closure인가요?

0

238

1

짧은 선언으로 변수 여러개를 만들때

0

241

1