TIL 17 - Golang으로 블록체인 만들기(서버 적용하기) 3

프동프동·2023년 2월 10일
0

TIL

목록 보기
17/46
post-thumbnail

Blockchain ↔ 백엔드 서버를 만들기 위한 build up 01

  • 소스 코드
    • main.go
      package main
      
      import (
      	"fmt"
      	"log"
      	"net/http"
      )
      
      const port string = ":4000"
      
      // request가 포인터인 이유(복사할 이유가 없기 떄문이다)
      // file이 될수도 있고 빅데이터가 될 수도 있기 떄문이다.
      func home(rw http.ResponseWriter, r *http.Request) {
      	// Fprint()는 io.Writer을 첫번째 인자로 받아 Writer에게 출력한다.
      	fmt.Fprint(rw, "Hello from home!")
      }
      func main() {
      	http.HandleFunc("/", home)
      
      	fmt.Printf("Listening on http://localhost%s\n", port)
      	// 에러가 있을때만 실행
      	log.Fatal(http.ListenAndServe(port, nil))
      }
  • 실행 결과
profile
좋은 개발자가 되고싶은

0개의 댓글