This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# python 3.7+ | |
from dataclasses import dataclass | |
@dataclass | |
class Product: | |
weight: int = None | |
price: float = None | |
apple = Product() | |
apple.price = 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_natural_number(): | |
n = 0 | |
while True: | |
n += 1 | |
yield n | |
get_natural_number() # <generator object get_natural_number at 0x10d3139d0> | |
g = get_natural_number() | |
for _ in range(0, 100): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "os" | |
func main() { | |
dir, err := os.Getwd() | |
if err != nil { | |
log.Fatal(err) | |
} | |
println(dir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Golang with Echo - starting Echo | |
// echo | |
// - echo는 엄청 큰 struct이다. | |
// - e := echo 여기서 e는 echo구조체를 가리키는 pointer | |
// e.GET(path, handleFunc, ...) | |
// - HandleFunc(context) 현재 request의 context이다. -> interface | |
// e.Logger.Print() / e.Logger.Fatal() | |
// Logger defines the logging interface. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ListenAndServe(addr string, handler Handler) error | |
// | |
package main | |
import ( | |
"fmt" | |
"net/http" | |
) | |
type MyWebserverType bool |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Gin? | |
// gin is a simple command line utility for live-reloading Go web applications. | |
// install : `go get github.com/codegangsta/gin` | |
// usage : gin --all -i run main.go | |
package main | |
import ( | |
"fmt" | |
"net/http" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//HandlerFunc(f) | |
// The HandlerFunc type is an adapter to allow the use of ordinary functions as HTTP handlers. | |
// If f is a function with the appropriate signature, HandlerFunc(f) is a Handler that calls f. | |
package main | |
import ( | |
"fmt" | |
"net/http" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//HandleFunc | |
// [!] HandlerFunc와 HandleFunc는 이름이 비슷하지만 다른함수이다. | |
// func HandleFunc(pattern string, handler func(ResponseWriter, *Request)) | |
// - localhost:8080/hello와 localhost:8080/login 그리고 각 endpoint에 대해서 GET, POST, DELETE 등 각각 다르게 동작해야한다. | |
// - 하드웨어 상이나, 다르게 Multiplexer를 이용하지만, echo Framework를 사용하기전 간단하게 HandleFunc로 구현해본다. | |
package main | |
import ( | |
"fmt" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Handle | |
// - Handle과 HandleFunc의 차이점은 2번째 parameter로 어떤 타입을 취급하냐이다. | |
// func Handle(pattern string, handler Handler) | |
// func HandleFunc(pattern string, handler func(ResponseWriter, *Request)) | |
package main | |
import ( | |
"fmt" | |
"net/http" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//http methods net/http | |
// - endpoint로 접근을 위한 다양한 방법 (GET, POST, ...)를 가진 request를 구분하는 방법 | |
// `r.Method`를 이용하여 처리한다. | |
// switch ~ case문을 이용하면 더 깔끔한 처리가 가능하다. (하지만, 복잡성에서는 선호하지 않는 방법이다.) | |
// Production 환경에서나, 실무 API Server를 구현할 때, switch문을 사용하면 complexity한 처리를 하지 못할 수도있다. | |
// 또 다른 방법으로는 different endpoint를 처리하는 Function을 두는 방법이 현명하다. | |
package main | |
import ( |
OlderNewer