Programming/golang2024. 1. 31. 17:35

찾아보니 존재는 하지만..

그래도 먼가 부족한 느낌? 내용이 부실해서 그런가..

페이지 넣는다거나 하는걸 찾아야 하는디..

 

[링크 : https://echo.labstack.com/docs/templates]

 

[링크 : https://www.digitalocean.com/community/tutorials/how-to-use-templates-in-go]

[링크 : https://stackoverflow.com/questions/33984147/golang-embed-html-from-file]

[링크 : https://pkg.go.dev/html/template]

[링크 : https://pkg.go.dev/text/template]

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

golang iota  (0) 2024.02.07
golang echo session check  (0) 2024.02.06
gin ui  (0) 2024.01.30
golang swagger part 2  (0) 2024.01.18
golang용 swagger  (0) 2024.01.17
Posted by 구차니
Programming/golang2024. 1. 30. 14:03

패키지 설치는 손쉬운데

go install gioui.org/cmd/gogio@latest

 

의존성이 어마어마 하다 -_-

apt install gcc pkg-config libwayland-dev libx11-dev libx11-xcb-dev libxkbcommon-x11-dev libgles2-mesa-dev libegl1-mesa-dev libffi-dev libxcursor-dev libvulkan-dev

[링크 : https://gioui.org/]

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

golang echo session check  (0) 2024.02.06
golang echo template engine  (0) 2024.01.31
golang swagger part 2  (0) 2024.01.18
golang용 swagger  (0) 2024.01.17
golang echo static web / logo.* 안돼?  (0) 2023.12.08
Posted by 구차니
Programming/golang2024. 1. 18. 10:55

어우 빡세 -_-

완전히 설정은 못했고

main.go의 주석문에 의해서 swag init 실행시에 초기화 하는데

그러다 보니 동적으로 타겟의 ip가 변경될 경우는 매번 주석을 변경해서 빌드해 주어야 하는 문제가 발생한다.

먼가 좋은 방법이 있나 찾아보는데 쓸만한 답은 못 찾음..

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

golang echo template engine  (0) 2024.01.31
gin ui  (0) 2024.01.30
golang용 swagger  (0) 2024.01.17
golang echo static web / logo.* 안돼?  (0) 2023.12.08
golang 타입 땜시 짜증  (0) 2023.11.10
Posted by 구차니
Programming/golang2024. 1. 17. 18:22

swagger도 이름이 생각안나서 한참 찾은...

해보면 묘하게 잘 안된다. swag 실행 파일도 그냥 swag에서 pre-built binary 받아서 실행해야 하고..

[링크 : https://yongho1037.tistory.com/791]

 

[링크 : https://github.com/go-swagger/go-swagger]

[링크 : https://github.com/swaggo/swag]

[링크 : https://github.com/swaggo/echo-swagger]

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

gin ui  (0) 2024.01.30
golang swagger part 2  (0) 2024.01.18
golang echo static web / logo.* 안돼?  (0) 2023.12.08
golang 타입 땜시 짜증  (0) 2023.11.10
golang 타입 캐스팅 제약(?)  (0) 2023.11.09
Posted by 구차니
Programming/golang2023. 12. 8. 11:30

logo.png나 logo.svg가 읽히지 않는 이상한 문제 발생

 

확인해보니 내부적으로 skipper를 이용해 log로 시작하면 스킵하도록 해놨는데

그걸 HasPrefix() 로 구현하다 보니, logo.svg나 log.png 에서 log로 시작하니 스킵되어 발생한 해프닝(?)

/log를 /log/로 바꾸면 문제없이 logo.png도 읽어온다.

e.Use(middleware.StaticWithConfig(middleware.StaticConfig{
Root: "html",
Skipper: func(c echo.Context) bool {
return strings.HasPrefix(c.Request().RequestURI, "/log")
},
}))

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

golang swagger part 2  (0) 2024.01.18
golang용 swagger  (0) 2024.01.17
golang 타입 땜시 짜증  (0) 2023.11.10
golang 타입 캐스팅 제약(?)  (0) 2023.11.09
golang 배열과 슬라이스  (0) 2023.11.08
Posted by 구차니
Programming/golang2023. 11. 10. 14:30

아놔.. 너무 심하게 강형 언어인거 아닌가 싶을 정도로

별별것 다 트집을 잡아서 명시적으로 형변환을 하게 만든다

time.Sleep(2 * time.Second) // 정상 작동

var update_sec int = 2
time.Sleep(update_sec * time.Second) // 에러

time.Sleep(time.Duration(update_sec) * time.Second) // 정상 작동

[링크 : https://jusths.tistory.com/71]

 

아니면 내가 너무 golang을 golang 답게 안쓰는건가?

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

golang용 swagger  (0) 2024.01.17
golang echo static web / logo.* 안돼?  (0) 2023.12.08
golang 타입 캐스팅 제약(?)  (0) 2023.11.09
golang 배열과 슬라이스  (0) 2023.11.08
golang ini 지원  (0) 2023.11.07
Posted by 구차니
Programming/golang2023. 11. 9. 10:58

눈에도 안들어 온다 으아아

[링크 : https://stackoverflow.com/questions/28040896/why-can-not-convert-sizebyte-to-string-in-go]

 

슬라이스를 배열로 하려면 copy 해야 하는 듯

package main
import "fmt"

//create main function to execute the program
func main() {
   var slice []int // initialize slice
   slice = append(slice, 10) //fill the slice using append function
   slice = append(slice, 20)
   slice = append(slice, 30)
   
   // Convert the slice to an array
   array := [3]int{} //initialized an empty array
   copy(array[:], slice) //copy the elements of slice in newly created array
   fmt.Println("The slice is converted into array and printed as:")
   fmt.Println(array) // prints the output: [10 20 30]
}

[링크 : https://www.tutorialspoint.com/golang-program-to-convert-slice-into-array]

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

golang echo static web / logo.* 안돼?  (0) 2023.12.08
golang 타입 땜시 짜증  (0) 2023.11.10
golang 배열과 슬라이스  (0) 2023.11.08
golang ini 지원  (0) 2023.11.07
golang 함수인자에 배열 포인터  (0) 2023.11.07
Posted by 구차니
Programming/golang2023. 11. 8. 22:34

다시 a tour of go 봐야 할 듯..

 

Arrays
The type [n]T is an array of n values of type T.

The expression

var a [10]int
declares a variable a as an array of ten integers.

An array's length is part of its type, so arrays cannot be resized. This seems limiting, but don't worry; Go provides a convenient way of working with arrays.

[링크 : https://go.dev/tour/moretypes/6]

 

 

Slices
An array has a fixed size. A slice, on the other hand, is a dynamically-sized, flexible view into the elements of an array. In practice, slices are much more common than arrays.

The type []T is a slice with elements of type T.

A slice is formed by specifying two indices, a low and high bound, separated by a colon:

a[low : high]
This selects a half-open range which includes the first element, but excludes the last one.

The following expression creates a slice which includes elements 1 through 3 of a:

a[1:4]

[링크 : https://go.dev/tour/moretypes/7]

 

 

크기가 정해지면 array, 정해지지않으면 slice인가?

Since you didn't specify the length, it is a slice.
An array type definition specifies a length and an element type: see "Go Slices: usage and internals"

[링크 : https://stackoverflow.com/questions/29361377/creating-a-go-slice-without-make]

 

 

갑자기 length와 capacity?!

A slice literal is declared just like an array literal, except you leave out the element count:

letters := []string{"a", "b", "c", "d"}

slice can be created with the built-in function called make, which has the signature,

func make([]T, len, cap) []T

where T stands for the element type of the slice to be created. The make function takes a type, a length, and an optional capacity. When called, make allocates an array and returns a slice that refers to that array.

var s []byte
s = make([]byte, 5, 5)
// s == []byte{0, 0, 0, 0, 0}

When the capacity argument is omitted, it defaults to the specified length. Here’s a more succinct version of the same code:

s := make([]byte, 5)

The length and capacity of a slice can be inspected using the built-in len and cap functions.

len(s) == 5
cap(s) == 5

[링크 : https://go.dev/blog/slices-intro]

 

 

실제 사용시에 capacity까지 알 필요는 없을려나?

capacity: 실제 메모리에 할당된 공간입니다. 만약 슬라이스에 요소를 추가하여 capacity가 가득차면 자동으로 늘어납니다.

[링크 : https://www.pymoon.com/entry/Go-튜토리얼-배열-슬라이스]

[링크 : https://phsun102.tistory.com/82]

[링크 : https://go.dev/tour/moretypes/11]

 

 

2차원 배열은 [][]type 으로 생성하면되는데

make를 통해서도 2차원 배열이 생성가능한진 모르겠다

package main

import "fmt"

func main() {
    // Step 1: create empty collection.
    values := [][]int{}

    // Step 2: these are the first two rows.
    // ... Append each row to the two-dimensional slice.
    row1 := []int{1, 2, 3}
    row2 := []int{4, 5, 6}
    values = append(values, row1)
    values = append(values, row2)

    // Step 3: display first row, and second row.
    fmt.Println("Row 1")
    fmt.Println(values[0])
    fmt.Println("Row 2")
    fmt.Println(values[1])

    // Step 4: access an element.
    fmt.Println("First element")
    fmt.Println(values[0][0])
}
Row 1
[1 2 3]
Row 2
[4 5 6]
First element
1

[링크 : https://www.dotnetperls.com/2d-go]

 

 

 

make와 := []type 두개가 동등하다면 가능할지도?

package main

import (
"fmt"
"strings"
)

func main() {
// Create a tic-tac-toe board.
board := [][]string{
[]string{"_", "_", "_"},
[]string{"_", "_", "_"},
[]string{"_", "_", "_"},
}

// The players take turns.
board[0][0] = "X"
board[0][2] = "X"
board[1][0] = "O"
board[1][2] = "X"
board[2][2] = "O"


for i := 0; i < len(board); i++ {
fmt.Printf("%s\n", strings.Join(board[i], " "))
}
}
X _ X
O _ X
_ _ O

[링크 : https://go.dev/tour/moretypes/14]

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

golang 타입 땜시 짜증  (0) 2023.11.10
golang 타입 캐스팅 제약(?)  (0) 2023.11.09
golang ini 지원  (0) 2023.11.07
golang 함수인자에 배열 포인터  (0) 2023.11.07
c to golang online converter  (0) 2023.11.07
Posted by 구차니
Programming/golang2023. 11. 7. 15:29

텍스트로 보이는 환경설정 파일로는 ini만한게 없지..

 

[링크 : https://pkg.go.dev/gopkg.in/ini.v1]

[링크 : https://github.com/go-ini/ini/]

[링크 : https://minwook-shin.github.io/read-and-write-ini-files-ini/]

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

golang 타입 캐스팅 제약(?)  (0) 2023.11.09
golang 배열과 슬라이스  (0) 2023.11.08
golang 함수인자에 배열 포인터  (0) 2023.11.07
c to golang online converter  (0) 2023.11.07
golang slice  (0) 2023.11.07
Posted by 구차니
Programming/golang2023. 11. 7. 14:38

c 들어내고 go로만 짜려니 어렵네..

함수 인자로 포인터를 넘겨줄 때에도 변수의 크기 정보가 넘어가야 한다.

그래서 정확한 포인터의 길이가 함수 인자에 지정되어야 한다.

그럼.. 굳이 포인터 쓸 필요가 없어지는거 아닌가?

 

// Golang program to pass a pointer to an 
// array as an argument to the function 
package main 
  
import "fmt"
  
// taking a function 
func updatearray(funarr *[5]int) { 
  
    // updating the array value 
    // at specified index 
    (*funarr)[4] = 750 
      
    // you can also write  
    // the above line of code 
    // funarr[4] = 750 

  
// Main Function 
func main() { 
  
    // Taking an pointer to an array 
    arr := [5]int{78, 89, 45, 56, 14} 
  
    // passing pointer to an array 
    // to function updatearray 
    updatearray(&arr
  
    // array after updating 
    fmt.Println(arr) 

[링크 : https://www.geeksforgeeks.org/golang-pointer-to-an-array-as-function-argument/]

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

golang 배열과 슬라이스  (0) 2023.11.08
golang ini 지원  (0) 2023.11.07
c to golang online converter  (0) 2023.11.07
golang slice  (0) 2023.11.07
golang echo bind  (0) 2023.11.06
Posted by 구차니