Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 채산성
- BTC
- nft민팅
- 코로나
- nft
- 스토리지코인
- 알위브
- 스토리지
- Mining
- datacap
- 데이터캡
- 암호화폐
- 코인
- 채굴
- 파일코인
- 이더리움
- filfox
- FIL
- 가상자산
- 공증인
- Q-code
- 바이낸스
- 파일코인플러스
- 레이어2
- 비트코인
- MATIC
- Arweave
- 투자
- FILECOIN
- 민팅
- Today
- 96
- Total
- 125,460
Blockchain & Devops, bitetiger
Go로 간단한 블록체인 구현하기 - CLI 본문
반응형
내가 구현한 블록체인과 통신할 수 있는 CLI를 구현해본다. flag를 사용해서 port와 사용할 mode를 설정한다.
package cli
import (
"flag"
"fmt"
"os"
)
func usage() {
fmt.Printf("This is vatacoin\n\n")
fmt.Printf("Please use the following flags:\n\n")
fmt.Printf("-port: Set the PORT of the server\n")
fmt.Printf("-mode: Choose between 'html' and 'rest'\n\n")
os.Exit(0)
}
func Start() {
if len(os.Args) == 1 {
usage()
}
port := flag.Int("port", 4000, "Set port of the server")
mode := flag.String("mode", "rest", "Choose between 'html' and 'rest'")
flag.Parse()
switch *mode {
case "rest":
rest.Start(*port)
case "html":
fmt.Println("there is no explorer")
default:
usage()
}
}
port := flag.Int("port", 4000, "Set port of the server")
port는 int로 선언하고, default 값은 4000으로 설정한다.
mode := flag.String("mode", "rest", "Choose between 'html' and 'rest'")
flag.Parse()
switch *mode {
case "rest":
rest.Start(*port)
case "html":
fmt.Println("there is no explorer")
default:
usage()
}
mode에서는 string으로 선언하고, default 값은 rest api로 설정한다. 아래 switch 문을 통해서 rest, html 중 입력값을 통해 함수를 호출한다.
반응형
'DevOps > Chain' 카테고리의 다른 글
Cosmos SDK란? (0) | 2023.01.10 |
---|---|
Go로 PoW 작업증명 알고리즘 구현하기 (0) | 2022.12.18 |
Go로 간단한 블록체인 구현하기 - REST API (0) | 2022.12.12 |
Go로 간단한 블록체인 구현하기 -2 (1) | 2022.12.03 |
Go언어로 간단한 블록체인 구현 (0) | 2022.11.29 |
0 Comments