$ 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) // 디코딩
$ 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바이트의 디스크 공간을 더 사용하게 됩니다.
#include <unistd.h> int access(const char *pathname, int mode);
The mode specifies the accessibility check(s) to be performed, and is either the value F_OK, or a mask consisting of the bitwise OR of one or more of R_OK, W_OK, and X_OK. F_OK tests for the existence of the file. R_OK, W_OK, and X_OK test whether the file exists and grants read, write, and execute permissions, respectively.