--- tags: - Gogolook type: slide --- The Interface of Golang === --- * Clean Architecture * Interface in Languages * Java * Ruby * TypeScript * Go * [Using interfaces in Go the right way](https://medium.com/@mbinjamil/using-interfaces-in-go-the-right-way-99384bc69d39) * Usage in Go --- ## Clean Architecture ![](https://i.imgur.com/9nPysrH.png) Controller 透過 InputBoundary(介面) 把資料傳遞給 UseCase --- ### Java ```java package com.example.usecase; public interface Input { public String Get() {} // ... } public class QueryInput implements Input { // ... } ``` ```java public class QueryUseCase { public void Get(Input input) { String id = input.Get("id"); // ... } } ``` --- ### TypeScript ```typescript public interface Input { Get(): string } public class QueryInput implements Input { // ... } ``` ```typescript class QueryUseCase { public void Get(input: Input) { string id = input.Get("id") } } ``` --- ### Ruby ```ruby class QueryInput def get; end end class QueryUseCase def get(input) id = input.get("id") end end ``` --- ### Go ```go package usecase type Input interface { Get() string } // ... func (u *QueryUsecase) Get(input Input) { id := input.Get() } ``` ```go package controller // ... func (i *QueryInput) Get() string { // ... } ``` --- ## Usage in Go * [Terraform Plugin](https://github.com/elct9620/terraform-provider-lambdalabs/blob/main/main.go#L29) * [io](https://pkg.go.dev/io#ReadWriter) * WRS Provider Interface