Go 언어



Go 1.13.5 설치 in windows

Go 다운로드 페이지에서 go 1.13.5.windows-amd64.msi 파일을 다운로드 하여 설치 한다.

Visual Stuio Code에서 Go extension을 설치하여 사용 한다.


Go 1.13.3 설치 in CentOS 7

yum  -y  install  golang

go  version

vi  zztemp.go
# go  run  ~.go

프로그램 문법

//--- 주석 : //, /* */

const  Pi  float64 = 3.141592           //--- 상수 선언
const  ~  =  iota

//--- 변수 : 문자, 숫자 (정수, 실수), 논리 / 배열, struct, interface / nil, itoa
var  strArray001 := []string{"aa", "bb"}
strArray001 = append(strArray001, "cc")
var  strArray002 := make([]string, len(strArray001))

var  ~  
var  ~  &[]string
var  ~  []int := [3]int{1, 2, 3}        //--- 0, 1, 2, ...
var  ~  =  nil
a, b := 1, 2
// [1:4], [1:], [:4]

type  Test  struct {
    a  int
    b  *[]int
    c  func()
    d  map[string] int
}

type  File  interface {
    Read([]byte) (int, error)
    Write([]byte) (int, error)
    Close() error
}

func min(x int, y int) int {
    if (x < y) {
        return x
    }
    return y
}
go  min(2, 3)


chan  T
make(chan int, 100)

//--- 제어문
if (~) {
} else if (~) {
} else { 
}

switch tag {
    case 0, 1, 2: ~
    default: ~
}
switch {
    case x < y: ~
       case x < z: ~
    case x == 4: ~
    default: ~
}

select {
    case x < y: ~
       case x < z: ~
    case x == 4: ~
    default: ~
}

OutLoop:
    for (a < b) {
        break OutLoop
        continue OutLoop
        goto theEnd
    }
theEnd:

for (i := 0; i < 3; i++) {
}

go  ~                                   //--- 별도의 Thread에서 실행

입출력


Go 언어 샘플

package 폴더 구조

  • bin
  • pkg
  • src
    • zztemp
      • zztemp001.go
vi  zztemp001.go
    package  main

    import  "fmt"
    import ("net/http")

    func main() {
        fmt.Println("Hello world.")

        http.HandleFunc("/hello", func(w http.ResponseWriter, req *http.Request) {
           w.Write([]byte("Hello world."))
        })

        http.ListenAndServe(":80", nil)
    }

go  run  zztemp001.go
# go  build  -o  zztemp001  zztemp001.go
# ./zztemp001
#--- http://localhost:80/hello

참고 문헌

최종 수정일: 2022-10-24 19:17:28

이전글 :
다음글 :
상단 menu
arrow_back_ios
arrow_forward_ios