Giter VIP home page Giter VIP logo

til's Introduction

TIL

๐Ÿคฏ 2020, Today I Learend
๋ฐฐ์šด ๋‚ด์šฉ์„ ๊นƒํ—ˆ๋ธŒ ๋˜๋Š” ์ด์Šˆ๋ฅผ ํ†ตํ•ด ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.


๐Ÿ—บ๏ธ ๋กœ๋“œ๋งต

JavaScript

TypeScript

Go

Flutter

til's People

Contributors

cjaewon avatar

Stargazers

 avatar ์ •ํ•œ Rycont avatar

Watchers

James Cloos avatar  avatar

til's Issues

Golang Struct pointer ์˜๋ฌธ์ ๊ณผ ์ด์œ 

type EXAMPLE struct {
    a int
}

example := &EXAMPLE{}
example2 := &EXAMPLE{}

fmt.Println(&example, &example2)
example = example2

fmt.Println(&example, &example2)

์œ„ ๊ฒฐ๊ณผ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

0xc0000ae018 0xc0000ae020
0xc0000ae018 0xc0000ae020

example = example2 ๋ฅผ ํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— ํฌ์ธํ„ฐ ์ฃผ์†Œ๊ฐ€ ๊ฐ™์•„์•ผ ๋œ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ๋‹ค.
example.a ์™€ example2.a ์˜ ๊ฐ’์„ ํ™•์ธํ•ด๋ณด๋‹ˆ ๊ฐ™์€ ๊ฑธ ์ธ์ง€ํ•˜์˜€๊ณ  ๋‚ด๊ฐ€ ํฌ์ธํ„ฐ์˜ ํฌ์ธํ„ฐ ์ฃผ์†Œ๋ฅผ ์ถœ๋ ฅํ•˜๊ณ  ์žˆ๋‹ค๋Š” ๊ฒƒ์„ ์•Œ๊ฒŒ๋ฌ๋‹ค.

์ฒ˜์Œ์—๋Š” ๋ฐ‘์— ์ฒ˜๋Ÿผ ์ƒ๊ฐํ–ˆ๋‹ค.
image

ํ•˜์ง€๋งŒ ์•Œ๊ณ ๋ณด๋‹ˆ ๋”๋ธ”ํฌ์ธํ„ฐ์˜ ์ฃผ์†Œ๋ฅผ ๊ฐ€์ ธ์˜ค๊ณ  ์žˆ์—ˆ๋˜ ๊ฒƒ์ด๋‹ค. ํฌ์ธํ„ฐ์˜ ํฌ์ธํ„ฐ ์ฃผ์†Œ๋Š” ์–ด์ฐจํ”ผ ๋‹ค๋ฅธ ๋ฉ”๋ชจ๋ฆฌ ๊ณต๊ฐ„์— ์ €์žฅ๋˜๋ฏ€๋กœ ๊ฐ™์„ ์ˆ˜๊ฐ€ ์—†๋‹ค.

fmt.Printf("%p %p", example, example2) // ํฌ์ธํ„ฐ๊ฐ€ ๊ฐ™๋‹ค. 

Golang mapstructure ํƒ€์ž… ์บ์ŠคํŠธ ๋ฐฉ๋ฒ•

์•„๋ž˜์ฒ˜๋Ÿผ ๋Œ€๋ฌธ์ž๋กœ ํ•ด์ฃผ์–ด์•ผ ์ ‘๊ทผ์ด ๊ฐ€๋Šฅํ•˜์—ฌ ๊ฐ’๋“ค์„ Decode ํ•œ ํ›„ ๋งตํ•‘ํ•ด์ค€๋‹ค.
์†Œ๋ฌธ์ž๋กœ ์ž‘์„ฑํ•ด์„œ Decode ํ• ๋•Œ ์˜ค๋ฅ˜๊ฐ€ ๋‚ฌ์—ˆ๋‹ค.

type Step struct {
	Name string                 `mapstructure:"name"`
	Run  string                 `mapstructure:"run"`
	Uses string                 `mapstructure:"uses"`
	With map[string]interface{} `mapstructure:"with"`
}

var steps []Step

trigger := config.GetString("on.push.trigger")
err := config.UnmarshalKey(fmt.Sprintf("jobs.%s.steps", trigger), &steps)

AWS lambda 502, 504 timeo out ์—๋Ÿฌ

AWS ์š”์ฒญ ์‹œ๊ฐ„์ด ์ง€๋‚˜๋ฉด 504 ์—๋Ÿฌ๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
์ •์ƒ์ ์œผ๋กœ ์ˆ˜ํ–‰๋˜๋Š” ๊ฒƒ ๊ฐ™์ง€๋งŒ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์—ฐ๊ฒฐ์„ ๋Š์–ด์ฃผ์ง€ ์•Š์•„์„œ timeout ์ด ๋˜๋Š” ์˜ค๋ฅ˜์˜€๋‹ค.

withCredentials :: ์ฟ ํ‚ค ๊ฐ™์ด ๋ณด๋‚ด๊ธฐ

๊ธฐ๋ณธ์€ origin์ด ๋‹ค๋ฅด๋ฉด ์ฟ ํ‚ค๋ฅผ ๋ณด๋‚ด์ง€ ์•Š๋Š”๋‹ค. ๋”ฐ๋ผ์„œ withCredentials : true ๋กœ ์„ค์ •ํ•œ ํ›„ ๋„๋ฉ”์ธ์„ ์ „์†กํ•ด์•ผํ•œ๋‹ค.
์ด ๊ฒฝ์šฐ์—๋Š” cors ๋˜ํ•œ ํ•ด๋‹น ๋„๋ฉ”์ธ์œผ๋กœ ์ •ํ™•ํ•˜๊ฒŒ ์„ค์ •ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค. ( * ์ด๋ฉด ์•ˆ๋จ )

carbon

Docker ์—์„œ Host ๋Š” ์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„์œผ๋กœ

docker-compose ์‚ฌ์šฉ ๋˜๋Š” network ์‚ฌ์šฉ ์ค‘ localhost ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์•ˆ๋˜๊ณ  ํ•ด๋‹น ์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„์œผ๋กœ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค. ๋Œ€ํ‘œ์ ์œผ๋กœ localhost:3306 ์ด ์•„๋‹ˆ๋ผ database:3306 ์œผ๋กœ ํ•ด์•ผํ•œ๋‹ค. ์ด๊ฒƒ ๋•Œ๋ฌธ์— 2์ผ์ด ๋‚ ๋ผ๊ฐ”๋‹ค. ๐Ÿ˜ญ

Rxjs Websocket next ๋Š” Object ๋กœ

๊ธฐ๋ณธ ์›น์†Œ์ผ“์€ Object ๋ฐ์ดํ„ฐ ๊ฐ’์„ ๋„˜๊ฒจ์ฃผ๊ธฐ ์œ„ํ•ด

  const string = JSON.stringify({ name, data });
  ws.send(string);

์œ„์™€ ๊ฐ™์€ ๋ฐฉ์‹์„ ์‚ฌ์šฉํ–ˆ๋‹ค. ํ•˜์ง€๋งŒ Rxjs ๋ฅผ ์‚ฌ์šฉํ• ๋•Œ๋Š”

// socket.js
const socket = webSocket(`${window.location.protocol === 'https:' ? 'wss' : 'ws'}://${location.host}`);

export default socket;
// index.js
socket.subscribe();

const request = { name, data };
socket.next(request);

์ด๋Ÿฐ ์‹์œผ๋กœ ์ŠคํŠธ๋ง์œผ๋กœ ๋ณ€๊ฒฝ์—†์ด Object๋กœ ๊ทธ๋ƒฅ ๋„˜๊ฒจ์ฃผ๋ฉด ๋œ๋‹ค. ๋‚ด๋ถ€์ ์œผ๋กœ String ์œผ๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ๊ฒƒ ๊ฐ™๋‹ค.
JSON.parse ํ•ด๋„ string type ์ด ๋‚˜์™€์„œ ๋†€๋ž๋Š”๋ฐ JSON.stringify ์„ ์‹œ์ผœ์ฃผ์–ด์„œ ๋ฐœ์ƒํ•œ ๋ฌธ์ œ์˜€๋‹ค.

Dockerfile COPY ๊ฒฝ๋กœ ์—๋Ÿฌ

ERROR: Service 'server' failed to build : COPY failed: no source files were specified
image

package.json ์„ ๊ฐ€์ ธ์˜ค๊ธฐ ์œ„ํ•ด ์ƒ์œ„์˜ ์ƒ์œ„ ํด๋”์—์„œ ๋ณต์‚ฌํ•˜๋„๋ก ๋งŒ๋“ค์—ˆ๋Š”๋ฐ ์œ„ ์‚ฌ์ง„๊ณผ ๊ฐ™์€ ์˜ค๋ฅ˜๊ฐ€ ๋–ณ๋‹ค. ์ด๋ฅผ ํ•ด๊ฒฐํ• ๋ ค๋ฉด Dockerfile ์ด๋ž€ ์„œ๋ฒ„๊ฐ€ ๊ฐ™์€ ์œ„์น˜์— ์žˆ์–ด์•ผ ํ•œ๋‹ค.

์Šคํƒ์˜ค๋ฒ„ํ”Œ๋กœ์šฐ ์—์„œ๋Š” ๋ฏธ๋ฆฌ ์ƒ์œ„์˜ ์ƒ์œ„ ํด๋”์—์„œ ๋นŒ๋“œํ•˜๊ณ  docker-compose up ํ•˜๊ธฐ๋ฅผ ๊ถŒ์žฅํ•˜๊ณ  ์žˆ๋‹ค.

Jenkins ๋„์ปค ๊ด€๋ จ ๋ฌธ์ œ ํ•ด๊ฒฐ๋ฐฉ๋ฒ• ( Jenkins in Docker )

๋„์ปค์˜ ์ปจํ…Œ์ด๋„ˆ ์•ˆ์—์„œ Jenkins๋ฅผ ๊ฐ€๋™ํ•˜๊ณ  ์žˆ์„ ๋•Œ
Jenkins ์—์„œ docker ๊ด€๋ จ ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•  ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋‹ค.

  volumes:
    - /var/run/docker.sock:/var/run/docker.sock
    - ../../volumns/jenkins_home:/var/jenkins_home  

์œ„์™€ ๊ฐ™์ด ๋„์ปค ๋ฐ๋ชฌ๊ณผ ์—ฐ๊ฒฐ์‹œ์ผœ์ฃผ์–ด์„œ ํ•ด๊ฒฐ ํ•  ์ˆ˜ ์žˆ๋‹ค.
์ด๋ฅผ ์œ„ํ•ด Jenkins ์— ๋„์ปค ํด๋ผ์ด์–ธํŠธ๋งŒ ๋”ฐ๋กœ ์„ค์น˜ํ•  ์ˆ˜ ์žˆ์ง€๋งŒ ๋ณ„๋กœ ์ข‹์€ ๋ฐฉ๋ฒ•์ด๋ผ๊ณ  ์ƒ๊ฐํ•˜์ง€๋Š” ์•Š์•˜๋‹ค.

  volumes:
    - /usr/bin/docker:/usr/bin/docker
    - /var/run/docker.sock:/var/run/docker.sock
    - ../../volumns/jenkins_home:/var/jenkins_home

๋”ฐ๋ผ์„œ /usr/bin/docker ๋˜ํ•œ ๊ฐ™์ด Volumn ์œผ๋กœ ์„ค์ •ํ•ด์ฃผ๋ฉด์„œ ํ•ด๊ฒฐํ•˜์˜€๋‹ค.
์†”์งํžˆ ์ข‹์€ ๋ฐฉ๋ฒ•์ธ์ง€๋Š” ์ž˜ ๋ชจ๋ฅด๊ฒ ๋‹ค. ๋„์ปค ํด๋ผ์ด์–ธํŠธ๋งŒ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•ด์ฃผ๋Š” plugin ์ด ์—†์„๊นŒ?

golang html/template ์—ฌ๋Ÿฌ ํŒŒ์ผ ์ฝ๊ธฐ

<!--  index.html  -->
{{ template "base.html" }}

{{ define "main" }}
  <h1>Hello World</h1>
  <a href="/hello">hello</a>
{{ end }}
<!--  hello.html  -->
{{ template "base.html" }}

{{ define "main" }}
  <a href="/">Travel it!</a>
{{ end }}
<!--  base.html  -->
<main>
  {{ block "main" . }}{{ end }}
</main>

์œ„์™€ ๊ฐ™์ด html ํ…œํ”Œ๋ฆฟ ์ฝ”๋“œ๋“ค์„ /web/layouts์™€ /web/pages ์— ์ •์˜ํ–ˆ๋‹ค.
๊ทธ๋ฆฌ๊ณ  ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ฝ”๋“œ๋ฅผ ํ†ตํ•ด์„œ ํŒŒ์‹ฑํ•ด์™”๋Š”๋ฐ {{ define }} ๋•Œ๋ฌธ์— index.html์˜ Tree๊ฐ€ hello.html ์™€ ๊ฐ™์€ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ–ˆ๋‹ค.. ์•„๋งˆ ์‹คํ–‰ํ•˜๊ธฐ์ „์— ํŒŒ์‹ฑํ•˜๋Š” ParseGlob ์—์„œ ๋ฐœ์ƒํ•œ ๋ฌธ์ œ์ธ ๊ฒƒ ๊ฐ™์•˜๋‹ค.

package templates

import (
	"errors"
	"html/template"
	"io"

	"github.com/labstack/echo/v4"
)

// Template is
type Template struct {
	templates *template.Template
}

// Render performances html/template rendering
func (t *Template) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
	return t.templates.ExecuteTemplate(w, name, data)
}

// New creates an instance of Template
func New() *Template {
	t := Template{
		templates: template.Must(template.ParseGlob("web/*/*.html")),
	}

	return &t
}

์ด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด templates์„ templateMap์œผ๋กœ ๋ณ€๊ฒฝ์‹œ์ผœ์ค€ ๋‹ค์Œ index.html, hello.html ์„ ๋”ฐ๋กœ๋”ฐ๋กœ base.html ๊ณผ ํ•ฉ์นœ ๋’ค ์ €์žฅํ•ด์ฃผ์—ˆ๋‹ค. ๋‹ค์Œ ์ฝ”๋“œ์™€ ๊ฐ™๋‹ค.

package templates

import (
	"html/template"
	"io"
	"path/filepath"

	"github.com/labstack/echo/v4"
)

// Template is
type Template struct {
	templateMap map[string]*template.Template
}

// Render performances html/template rendering
func (t *Template) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
	return t.templateMap[name].ExecuteTemplate(w, "base.html", data)
}

// New creates an instance of Template
func New() *Template {
	t := Template{
		templateMap: map[string]*template.Template{},
	}

	layouts := template.Must(template.ParseGlob("web/layouts/*.html"))

	pages, err := filepath.Glob("web/pages/*.html")
	if err != nil {
		panic(err)
	}

	for _, file := range pages {
		base := filepath.Base(file)
		tmpl := template.Must(template.ParseFiles(file))
		tmpl.AddParseTree(layouts.Tree.Name, layouts.Tree)

		t.templateMap[base] = tmpl
	}

	return &t
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.