'Programming/golang'에 해당되는 글 107건

  1. 2022.04.04 liteide
  2. 2022.03.31 golang gore(repl), delve
  3. 2022.03.31 go build 옵션
  4. 2022.03.10 go lang static http server
  5. 2022.02.17 go hello world build static / shared
  6. 2022.02.11 go lang rest
  7. 2020.05.18 golang
Programming/golang2022. 4. 4. 14:56

ubuntu 18.04에 gqrx를 먼저 깔면서 qt5가 추가된 것 같긴한데

예전의 QT가 아닌지 빠릿빠릿하게 실행되는 느낌!

 

아무튼 golang 용 ide인데 api 조회가 쉬우면 좋겠네

[링크 : http://liteide.org/en/]

[링크 : https://streamls.tistory.com/54]

 

$ sudo snap install liteide-tpaw

[링크 : https://ubunlog.com/ko/go를위한-liteide-개발-환경/]

'Programming > golang' 카테고리의 다른 글

go 모듈 불러오기  (0) 2022.04.06
golang 다른 파일 함수 불러오기  (0) 2022.04.04
golang gore(repl), delve  (0) 2022.03.31
go build 옵션  (0) 2022.03.31
go lang static http server  (0) 2022.03.10
Posted by 구차니
Programming/golang2022. 3. 31. 23:52

node.js나 python 같은 인터프리트 언어가 대세라 그런가..

컴파일 언어를 인터프리트 언어 처럼 쓰게 해주는 환경이라니..

REPL(read-eval-print loop)

[링크 : https://github.com/x-motemen/gore]

[링크 : https://gorepl.com/]

[링크 : https://tkim.info/ko/devnote/d054-gore쓰다가-답답해서-tour-of-go-설치해서-쓴-썰/]

 

delve는 디버거 패키지.. 아니 툴이라고 해야하나?

[링크 : https://www.joinc.co.kr/w/man/12/golang/delve]

'Programming > golang' 카테고리의 다른 글

golang 다른 파일 함수 불러오기  (0) 2022.04.04
liteide  (0) 2022.04.04
go build 옵션  (0) 2022.03.31
go lang static http server  (0) 2022.03.10
go hello world build static / shared  (0) 2022.02.17
Posted by 구차니
Programming/golang2022. 3. 31. 19:05

gcc와 유사한 옵션들이군..

 

-o 옵션을 통해 실행파일 이름을 지정할 수 있는데, 지정하지 않을 경우 소스코드의 이름을 출력이름으로 지정한다.

go build [-o output] [build flags] [packages]

[링크 : https://pkg.go.dev/cmd/go]

 

 

$ go build -linkshared filename.go

옵션을 통해 빌드할때

open /usr/lib/go-1.17/pkg/linux_amd64_dynlink/archive/zip.shlibname: permission denied

권한이 부족해서 거부되었다는 에러가 발생하는데 대개는 sudo를 주고 하지만

왜 발생하나 궁금해서 찾아보니

dynlink에 파일들이 linkshared 옵션으로 빌드할때 날짜가 변경되는 것으로 보인다.

*.a 나 libstd.so 들 역시 변경되는걸 봐서는 linkshared로 빌드할때 해당 so도 같이 빌드 하는 듯.

[링크 : https://superuser.com/questions/739738/how-to-use-go-get-as-non-root]

 

dynlink 에서 GOROOT라는 변수가 보이길래 보는데 선언된건 없고..

$ cd $GOROOT/pkg/linux_amd64_dynlink
$ ls libstd.so
libstd.so

[링크 : https://www.codestudyblog.com/cs2112goa/1212131010.html]

 

도움말 보다보니 env라는 명령어 발견

$ go --help
Go is a tool for managing Go source code.

Usage:

        go <command> [arguments]

The commands are:

        bug         start a bug report
        build       compile packages and dependencies
        clean       remove object files and cached files
        doc         show documentation for package or symbol
        env         print Go environment information
        fix         update packages to use new APIs
        fmt         gofmt (reformat) package sources
        generate    generate Go files by processing source
        get         add dependencies to current module and install them
        install     compile and install packages and dependencies
        list        list packages or modules
        mod         module maintenance
        run         compile and run Go program
        test        test packages
        tool        run specified go tool
        version     print Go version
        vet         report likely mistakes in packages

Use "go help <command>" for more information about a command.

Additional help topics:

        buildconstraint build constraints
        buildmode       build modes
        c               calling between Go and C
        cache           build and test caching
        environment     environment variables
        filetype        file types
        go.mod          the go.mod file
        gopath          GOPATH environment variable
        gopath-get      legacy GOPATH go get
        goproxy         module proxy protocol
        importpath      import path syntax
        modules         modules, module versions, and more
        module-get      module-aware go get
        module-auth     module authentication using go.sum
        packages        package lists and patterns
        private         configuration for downloading non-public code
        testflag        testing flags
        testfunc        testing functions
        vcs             controlling version control with GOVCS

Use "go help <topic>" for more information about that topic.

 

$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/minimonk/.cache/go-build"
GOENV="/home/minimonk/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/minimonk/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/minimonk/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go-1.17"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.17/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17.8"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1772520358=/tmp/go-build -gno-record-gcc-switches"

 

저 놈의 GOTOOLDIR을 바꾸어 주면 되려나?

 

GOOS와 GOARCH를 이용해서 크로스컴파일 가능하다고 한다.

$ env GOOS=windows GOARCH=amd64 go build source.go

[링크 : https://www.digitalocean.com/community/tutorials/how-to-build-go-executables-for-multiple-platforms-on-ubuntu-16-04]

 

이게 되네..

$ GOARCH=arm go build hello.go
$ file hello
hello: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, not stripped

$ GOARCH=arm64 go build hello.go
$ file hello
hello: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, not stripped

 

'Programming > golang' 카테고리의 다른 글

liteide  (0) 2022.04.04
golang gore(repl), delve  (0) 2022.03.31
go lang static http server  (0) 2022.03.10
go hello world build static / shared  (0) 2022.02.17
go lang rest  (0) 2022.02.11
Posted by 구차니
Programming/golang2022. 3. 10. 19:09

의외로 무지 단순하게 추가가 가능.

아무튼 경로가 겹치지만 않으면 REST API랑 같이 가능하지 않을까 싶은데

이 경우에는 누가 우선순위를 가질지

먼저 등록된 쪽이려나 아니면 별도의 REST로 등록한 쪽이 우선이려나?

 

package main
 
import (
    "net/http"
)
 
func main() {   
    http.Handle("/", http.FileServer(http.Dir("wwwroot")))
    http.ListenAndServe(":5000", nil)
}

[링크 : http://golang.site/go/article/111-간단한-웹-서버-HTTP-서버]

'Programming > golang' 카테고리의 다른 글

golang gore(repl), delve  (0) 2022.03.31
go build 옵션  (0) 2022.03.31
go hello world build static / shared  (0) 2022.02.17
go lang rest  (0) 2022.02.11
golang  (0) 2020.05.18
Posted by 구차니
Programming/golang2022. 2. 17. 18:26

 

$ vi hello.go
$ go build hello.go 
$ go run hello.go 
hello world

$ file hello
hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, with debug_info, not stripped

$ ldd hello
동적 실행 파일이 아닙니다

$ ls -alh
-rwxrwxr-x 1 minimonk minimonk 2.0M  2월 17 18:25 hello
-rw-rw-r-- 1 minimonk minimonk   73  2월 17 18:25 hello.go

[링크 : https://gobyexample.com/hello-world]

 

+

go install 부분을 sudo로 해서 그런가 go build도 sudo를 하지 않으면 안된다.

퍼미션 문제는 어떻게 해결할 수 있으려나...

 

$ go install -buildmode=shared std
$ sudo go build -linkshared hello.go
ls -alh
$ ls -alh
합계 32K
-rwxr-xr-x 1 root     root      20K  2월 17 18:28 hello
-rw-rw-r-- 1 minimonk minimonk   73  2월 17 18:25 hello.go

$ ldd hello
linux-vdso.so.1 (0x00007ffcfb5a4000)
libstd.so => /usr/lib/go-1.10/pkg/linux_amd64_dynlink/libstd.so (0x00007f2647852000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2647461000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f264725d000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f264703e000)
/lib64/ld-linux-x86-64.so.2 (0x00007f2649ee5000)

[링크 : https://stackoverflow.com/questions/19431296/building-and-linking-dynamically-from-a-go-binary]

 

+

2022.02.18

$ ls -alh /usr/lib/go-1.10/pkg/linux_amd64_dynlink/*so
-rw-r--r-- 1 root root 31M  2월 17 18:28 /usr/lib/go-1.10/pkg/linux_amd64_dynlink/libstd.so

$ ldd libstd.so 
linux-vdso.so.1 (0x00007ffcbe083000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f379ff4e000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f379fd2f000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f379f93e000)
/lib64/ld-linux-x86-64.so.2 (0x00007f37a25e1000)

'Programming > golang' 카테고리의 다른 글

golang gore(repl), delve  (0) 2022.03.31
go build 옵션  (0) 2022.03.31
go lang static http server  (0) 2022.03.10
go lang rest  (0) 2022.02.11
golang  (0) 2020.05.18
Posted by 구차니
Programming/golang2022. 2. 11. 19:38

node.js 처럼 go mod init 명령을 통해 모듈을 설치할 수 있는 것 같다.

 

go 1.10은 지원도 끊어졌고 해당 명령어 지원하지 않으니

g0 1.11은 가야 할 것 같다.

[링크 : https://stackoverflow.com/questions/60410729/unknown-subcommand-mod-error-while-running-go-mod-init]

 

아래껀 천천히 테스트 해봐야겠네..

(우분투 20.04로 가야하나...)

go mod init noah.io/ark/rest
$ vi main.go
package main

import (
"encoding/json"
"net/http"
)

var users = map[string]*User{}

type User struct {
Nickname string `json:"nickname"`
Email    string `json:"email"`
}

func main() {
http.HandleFunc("/users", func(wr http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet: // 조회
json.NewEncoder(wr).Encode(users) // 인코딩
case http.MethodPost: // 등록
var user User
json.NewDecoder(r.Body).Decode(&user) // 디코딩

users[user.Email] = &user

json.NewEncoder(wr).Encode(user) // 인코딩
}
})
http.ListenAndServe(":8080", nil)
}

[링크 : https://woony-sik.tistory.com/m/12]

 

$ go get github.com/julienschmidt/httprouter
$ vi rest.go
package main

import (
    "fmt"
    "github.com/julienschmidt/httprouter"
    "net/http"
    "log"
)

func Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
    fmt.Fprint(w, "Welcome!\n")
}

func Hello(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
    fmt.Fprintf(w, "hello, %s!\n", ps.ByName("name"))
}

func main() {
    router := httprouter.New()
    router.GET("/", Index)
    router.GET("/hello/:name", Hello)

    log.Fatal(http.ListenAndServe(":8080", router))
}

[링크 : https://okky.kr/article/386116]

 

+

backport를 깔아주면 된다고는 한다.

$ sudo add-apt-repository ppa:longsleep/golang-backports
$ sudo apt-get install software-properties-common
$ sudo apt-get update 
$ sudo apt-get install golang-1.11

[링크 : https://www.gophp.io/install-go-1-11-on-ubuntu-18-04/]

 

추가해보니 1.18까지도 나왔나 보다.

$ sudo add-apt-repository ppa:longsleep/golang-backports
Golang 1.8, 1.9, 1.10, 1.11, 1.12, 1.13, 1.14, 1.15, 1.16, 1.17 and 1.18 PPA for Ubuntu
 더 많은 정보: https://launchpad.net/~longsleep/+archive/ubuntu/golang-backports
[ENTER]을 눌러 진행하거나 Ctrl-c를 눌러 추가하는것을 취소합니다.

 

그래도 1.17을 기준으로 설치 되는 듯.

$ sudo apt-get install golang
패키지 목록을 읽는 중입니다... 완료
의존성 트리를 만드는 중입니다
상태 정보를 읽는 중입니다... 완료
다음 패키지가 자동으로 설치되었지만 더 이상 필요하지 않습니다:
  golang-1.10-go golang-1.10-race-detector-runtime golang-1.10-src
  golang-1.11-doc golang-1.11-go golang-1.11-race-detector-runtime
  golang-1.11-src golang-race-detector-runtime
Use 'sudo apt autoremove' to remove them.
다음의 추가 패키지가 설치될 것입니다 :
  golang-1.17 golang-1.17-doc golang-1.17-go golang-1.17-src golang-doc
  golang-go golang-src
제안하는 패키지:
  bzr | brz mercurial subversion
다음 새 패키지를 설치할 것입니다:
  golang golang-1.17 golang-1.17-doc golang-1.17-go golang-1.17-src golang-doc
다음 패키지를 업그레이드할 것입니다:
  golang-go golang-src
2개 업그레이드, 6개 새로 설치, 0개 제거 및 1개 업그레이드 안 함.
72.0 M바이트 아카이브를 받아야 합니다.
이 작업 후 424 M바이트의 디스크 공간을 더 사용하게 됩니다.

'Programming > golang' 카테고리의 다른 글

golang gore(repl), delve  (0) 2022.03.31
go build 옵션  (0) 2022.03.31
go lang static http server  (0) 2022.03.10
go hello world build static / shared  (0) 2022.02.17
golang  (0) 2020.05.18
Posted by 구차니
Programming/golang2020. 5. 18. 21:53

go 에서 검색하기 힘드니 이제 golang이라고도 하는 듯

윈도우용  바이너리도 제공은 하는데 native 일려나?

 

[링크 : https://golang.org/dl/]

 

 

흐음.. 키워드만 봐서는 java, python이 떠오르네

[링크 : https://github.com/golang/go/wiki/Ubuntu]

'Programming > golang' 카테고리의 다른 글

golang gore(repl), delve  (0) 2022.03.31
go build 옵션  (0) 2022.03.31
go lang static http server  (0) 2022.03.10
go hello world build static / shared  (0) 2022.02.17
go lang rest  (0) 2022.02.11
Posted by 구차니