Skip to content
GwiyeomGo Tech Blog
About GwiyeomGo

Golang(Go) Interface 를 사용해서 코드를 구성해 보자

GOLANG, 20221 min read

인터페이스 go에는 클레스와 상속이 없다

type A interface

하나의 기능을

오버라이딩 = 재정의

메서드의 묶음을 새로운 타입으로 선언한것이 인터페이스 즉 중간역할 연결자

덕 타이핑 인터페이스 여부를 확인할때 사용한다

인터페이스 => 오버라이딩?

택배랑 매장 등록을 양쪽에서하는데 조금씩 다름 중복되는게 너무 많으니까 인터페이스를 사용해서 맞춰서 쓰고 있음

validate campaign

type DonationInterface interface {
SetCampaign(string, string, string)
SetSiteCode(string)
}

map에서 interface 타입은 그냥 값이 없는 상태로 위에서 말하는 것과 다름

interface type to map[string]string 으로 convert

var in interfcase{}
...
v, ok := in.(map[string]string)
if !ok {
// handle error.
}
for _, s := range v {
fmt.Printf("Value: %v\n", s)
}

참고

https://stackoverflow.com/questions/38185916/how-to-convert-interface-to-map

© 2024 by GwiyeomGo Tech Blog. All rights reserved.