sonumb

Go 언어 소스코드를 UML로 리버스 엔지니어링 하기 본문

개발자 이야기/Go

Go 언어 소스코드를 UML로 리버스 엔지니어링 하기

sonumb 2020. 8. 25. 15:41

개요

Go 언어로 작성된 소스코드로부터 UML로 리버스 해주는 도구를 소개하고, 그 사용법과 예시를 보여준다.

1. plantuml

plantuml은 UML을  puml이라는 특정 마크업 언어로 표현한 것이다.

puml로 작성된 파일을 그림으로 출력할 수 있는 툴을 제공한다.

1.1. 다운로드

https://plantuml.com/ko/download 에 가서 plantuml.jar를 $HOME/bin에 다운 받는다.

($HOME/bin 이 아니라도 상관없다. 다만 아래에서 $HOME/bin/plantuml.jar 를 다른 경로로 변경해야 함.)

2. goplantuml

go 언어로 작성된 소스코드들을 분석하여 puml을 출력한다.

https://github.com/jfeliu007/goplantuml에 설치방법 및 실행 방법에 대해 자세히 설명해놓았다.

2.1. 설치

go get github.com/jfeliu007/goplantuml/parser
go get github.com/jfeliu007/goplantuml/cmd/goplantuml
cd $GOPATH/src/github.com/jfeliu007/goplantuml
go install ./...

2.2. puml 생성

위 명령어 실행시 결과물이 화면(stdout)에 출력된다. 따라서 리다이렉션으로 파일을 저장할 수 있다.

goplantuml [-recursive] path/to/gofiles path/to/gofiles2 > outfile.puml

2.3. puml 로 부터 png 파일 생성

java -jar $HOME/bin/plantuml.jar outfile.puml

위 명령어로 outfile.png 가 생성된다. 즉, 이름은 같고 확장자가 png인 그림 파일이 생성.

3.예시

3.1. 소스코드로 부터 UML과 그림 생성하기

cd ~/work/ git clone https://github.com/vitessio/vitess.git vitess_2.1
cd vitess_2.1
git checkout -t origin/release-2.1
cd go/sqltypes goplantuml -recursive . > sqltypes.puml
java -jar $HOME/bin/plantuml.jar sqltypes.puml

3.2. 결과

반응형