'Programming'에 해당되는 글 1767건

  1. 2022.09.05 jquery-cookie 라이브러리
  2. 2022.09.02 golang 쿠키
  3. 2022.09.02 golang http redirect
  4. 2022.09.02 golang html form post 처리하기
  5. 2022.08.31 golang http.HandleFunc(pattern)
  6. 2022.08.30 golang mariadb 연동
  7. 2022.08.29 MSB / LSB 변환
  8. 2022.08.24 JWT 로그인 예제
  9. 2022.08.18 golang channel
  10. 2022.08.08 quirks mode
Programming/jquery2022. 9. 5. 11:57

서버에서 request cookie로 보내면 document.cookie로 접근이 가능한데

그걸 간단하게 사용하기 위한 라이브러리

[링크 : https://hailey0.tistory.com/38]

 

 

function getCookie(cname) {
  let name = cname + "=";
  let decodedCookie = decodeURIComponent(document.cookie);
  let ca = decodedCookie.split(';');
  for(let i = 0; i <ca.length; i++) {
    let c = ca[i];
    while (c.charAt(0) == ' ') {
      c = c.substring(1);
    }
    if (c.indexOf(name) == 0) {
      return c.substring(name.length, c.length);
    }
  }
  return "";
}

[링크 : https://www.w3schools.com/js/js_cookies.asp]

 

[링크 : https://nowonbun.tistory.com/634]

 

그나저나  document.cookie가 왜이렇게 생소하지?

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

jquery ajax auth  (0) 2023.07.27
jquery ajax delete가 없다?  (0) 2022.09.16
jquery 우클릭 가로채기  (0) 2019.06.04
jquery ajax json flask  (0) 2019.01.07
jquery this 버튼 checked  (0) 2019.01.07
Posted by 구차니
Programming/golang2022. 9. 2. 16:44

 

func createCookie(w http.ResponseWriter, req *http.Request) { 
    http.SetCookie(w, &http.Cookie{
        Name: "name of cookie",
        Value: "value of cookie",
        Path: "/",
    })
}

func expireCookie(w http.ResponseWriter, req *http.Request) {
    cookie, err := r.Cookie("cookie-name")
    
    if err := nil{
    }
    // 1. 쿠키 삭제
    // cookie.MaxAge = -1
    
    // 2. 쿠키를 5초간 지속
    // cookie.MaxAge = 5
    
    // 3. expires 설정, 현재시간으로 부터 1시간 뒤 == 쿠키의 만료시각
    // expiration := time.Now().Add(time.Hour)
    // cookie.Expires = expiration
    
    http.SetCookie(w, cookie)
    http.Redirect(w, req, "/", http.StatusSeeOther)
}

[링크 : https://velog.io/@j1mmyson/golang-go언어에서의-쿠키-사용]

[링크 : https://pkg.go.dev/net/http#Request.Cookie]

[링크 : https://pkg.go.dev/net/http#SetCookie]

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

go 루틴  (0) 2022.09.06
golang https server  (0) 2022.09.05
golang http redirect  (0) 2022.09.02
golang html form post 처리하기  (0) 2022.09.02
golang http.HandleFunc(pattern)  (0) 2022.08.31
Posted by 구차니
Programming/golang2022. 9. 2. 16:29

form post 로 받아서 DB로 조회하고 성공시, 어떻게 다른 링크로 돌려보내나 고민을 했는데

http.Redirect()라는 함수를 발견. StatusSeeOther는 303 코드인데 좀.. 생소하네?

 

if r.Method == "POST" {
    saveChoice(r.Form["choices"])
    http.Redirect(w, r, newUrl, http.StatusSeeOther)
}

[링크 : https://stackoverflow.com/questions/35934298/how-to-redirect-to-a-url]

 

특이하게도.. Response와 Request 둘다 들어와야 쓸 수 있는 녀석.

func Redirect(w ResponseWriter, r *Request, url string, code int)
Redirect replies to the request with a redirect to url, which may be a path relative to the request path.

The provided code should be in the 3xx range and is usually StatusMovedPermanently, StatusFound or StatusSeeOther.

If the Content-Type header has not been set, Redirect sets it to "text/html; charset=utf-8" and writes a small HTML body. Setting the Content-Type header to any value, including nil, disables that behavior.

[링크 : https://pkg.go.dev/net/http#Redirect]

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

golang https server  (0) 2022.09.05
golang 쿠키  (0) 2022.09.02
golang html form post 처리하기  (0) 2022.09.02
golang http.HandleFunc(pattern)  (0) 2022.08.31
golang mariadb 연동  (0) 2022.08.30
Posted by 구차니
Programming/golang2022. 9. 2. 15:31

오랫만에 HTML 하니 다 까먹었네..

html 에서는 아래와 같이 post로 넘겨줄 변수 명은 name에 기재하고 form method를 post로 해주면 끝!

다만 action은 생략될 수 있으므로 처리해야할 페이지의 링크를 기록해주면 된다.

<form method="post" action="url">
<intut type="text" name="username">
</form>

 

func loginHandler(wr http.ResponseWriter, r *http.Request) {
        r.ParseForm()
        switch r.Method {
                case http.MethodPost: // 조회
                        fmt.Println(r)
                        fmt.Println(r.Form)
                        fmt.Println(r.PostForm)
                        fmt.Fprintln(wr, r.Form)
        }
}

[링크 : https://dksshddl.tistory.com/entry/Go-web-programming-request-처리-및-response-작성]

 

ParseForm() 을 실행하지 않으면, r.Form이 업데이트 되지 않아 내용이 조회가 되지 않는다.

ParseForm populates r.Form and r.PostForm.

For all requests, ParseForm parses the raw query from the URL and updates r.Form.

For POST, PUT, and PATCH requests, it also reads the request body, parses it as a form and puts the results into both r.PostForm and r.Form. Request body parameters take precedence over URL query string values in r.Form.

If the request Body's size has not already been limited by MaxBytesReader, the size is capped at 10MB.

For other HTTP methods, or when the Content-Type is not application/x-www-form-urlencoded, the request Body is not read, and r.PostForm is initialized to a non-nil, empty value.

ParseMultipartForm calls ParseForm automatically. ParseForm is idempotent.

[링크 : https://pkg.go.dev/net/http#Request.ParseForm]

 

html post를 직접 하는건데 유용한(?) 라이브러리가 보여서 링크!

import "encoding/json"
import "encoding/xml"

[링크 : http://golang.site/go/article/103-HTTP-POST-호출]

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

golang 쿠키  (0) 2022.09.02
golang http redirect  (0) 2022.09.02
golang http.HandleFunc(pattern)  (0) 2022.08.31
golang mariadb 연동  (0) 2022.08.30
golang channel  (0) 2022.08.18
Posted by 구차니
Programming/golang2022. 8. 31. 18:00

golang을 이용해서 rest 서버를 만드는데 가장 만만한(?) 녀석은

net/http 모듈의 http.HandleFunc() 인데

 

pattern 이라고 써넣고는 막상 설명이 없다.

func HandleFunc(pattern string, handler func(ResponseWriter, *Request))

[링크 : https://pkg.go.dev/net/http#HandleFunc]

 

음.. 소스를 봐도 모르겠다.

// Handle registers the handler for the given pattern.
// If a handler already exists for pattern, Handle panics.
func (mux *ServeMux) Handle(pattern string, handler Handler) {
mux.mu.Lock()
defer mux.mu.Unlock()

if pattern == "" {
panic("http: invalid pattern")
}
if handler == nil {
panic("http: nil handler")
}
if _, exist := mux.m[pattern]; exist {
panic("http: multiple registrations for " + pattern)
}

if mux.m == nil {
mux.m = make(map[string]muxEntry)
}
e := muxEntry{h: handler, pattern: pattern}
mux.m[pattern] = e
if pattern[len(pattern)-1] == '/' {
mux.es = appendSorted(mux.es, e)
}

if pattern[0] != '/' {
mux.hosts = true
}
}

[링크 : https://cs.opensource.google/go/go/+/refs/tags/go1.19:src/net/http/server.go;drc=ddc93a536faf4576d182cd3197b116d61d05c484;l=2480]

 

걍.. gin 모듈을 쓰는게 속 편하려나?

[링크 : https://stackoverflow.com/questions/6564558/wildcards-in-the-pattern-for-http-handlefunc]

 

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

golang http redirect  (0) 2022.09.02
golang html form post 처리하기  (0) 2022.09.02
golang mariadb 연동  (0) 2022.08.30
golang channel  (0) 2022.08.18
golang unused import  (0) 2022.07.20
Posted by 구차니
Programming/golang2022. 8. 30. 12:31

테스트 해보니

localhost:3306 접속시에는 username:password@/dbname 식으로 접속해도 된다.

 

db, _ := sql.Open("mysql", "dellis:@/shud")

[링크 : https://mariadb.com/ko/resources/blog/using-go-with-mariadb/]

[링크 : https://pkg.go.dev/database/sql]

 

db, err := sql.Open("mysql", "root:pwd@tcp(127.0.0.1:3306)/testdb")

[링크 : http://golang.site/go/article/107-MySql-사용---쿼리]

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

golang html form post 처리하기  (0) 2022.09.02
golang http.HandleFunc(pattern)  (0) 2022.08.31
golang channel  (0) 2022.08.18
golang unused import  (0) 2022.07.20
golang websocket package  (0) 2022.07.15
Posted by 구차니
Programming/C Win32 MFC2022. 8. 29. 11:43

무슨 마법인진 모르겠다.

아무튼.. for  문으로 32bit를 뒤집으려면

최소한 비트 * 5 이상의 연산이 필요할텐데(쉬프트, and , or, for문 비교, for문 증가)

 

[링크 : https://stackoverflow.com/questions/746171/efficient-algorithm-for-bit-reversal-from-msb-lsb-to-lsb-msb-in-c]

'Programming > C Win32 MFC' 카테고리의 다른 글

free(): invalid next size (normal)  (0) 2023.12.18
c에서 cpp 함수 불러오기  (0) 2023.01.04
kore - c restful api server  (0) 2022.07.07
fopen exclusivly  (0) 2021.07.09
vs2019 sdi , mdi 프로젝트 생성하기  (0) 2021.07.08
Posted by 구차니
Programming/web 관련2022. 8. 24. 18:05

음.. 환상이 컸었나..

지금 다시 보는데 POST로 id, pw를 plain text로 보내는 센스..

서버가 https로 보안채널이 되었다고 가정하지 않으면 의미없는 짓 같은 느낌..

 

[링크 : https://llshl.tistory.com/28]

[링크 : https://minho-jang.github.io/development/7/]

[링크 : https://velopert.com/2389]

 

SSO 구현에 JWT가 가능한진 좀 찾아봐야겠다.

[링크 : https://brunch.co.kr/@sangjinkang/36]

'Programming > web 관련' 카테고리의 다른 글

chart.js log 스케일  (0) 2023.03.31
chatGPT님 가라사대 Server-Sent Events (SSE)  (0) 2023.03.15
quirks mode  (0) 2022.08.08
grid와 flex  (0) 2022.07.04
web gl on chrome  (0) 2021.12.14
Posted by 구차니
Programming/golang2022. 8. 18. 12:18

<-

이런 연산자가 보여서 먼가 찾아보는 중

 

[링크 : https://etloveguitar.tistory.com/40]

[링크 : https://go.dev/ref/spec#Receive_operator]

[링크 : https://go.dev/ref/spec#Channel_types]

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

golang http.HandleFunc(pattern)  (0) 2022.08.31
golang mariadb 연동  (0) 2022.08.30
golang unused import  (0) 2022.07.20
golang websocket package  (0) 2022.07.15
go run ./  (2) 2022.04.18
Posted by 구차니
Programming/web 관련2022. 8. 8. 17:26

귀찮아서 html 대충 만들다 보니

처음 부분에 <!DOCTYPE html>을 뺴먹었더니

크롬 개발자 도구에 아래와 같은 issue가 발생해서 클릭해보니.. 이상한게 보인다.

 

[링크 : https://web.dev/doctype/?utm_source=devtools]

 

굳이 해석(?)하자면

html5, css 표준 제정 이전 레거시 브라우저  호환성 지원? 이라고 보면 되려나?

[링크 : https://a-tothe-z.tistory.com/4]

[링크 : https://developer.mozilla.org/en-US/docs/Web/HTML/Quirks_Mode_and_Standards_Mode]

[링크 : https://aboooks.tistory.com/169]

[링크 : https://en.wikipedia.org/wiki/Quirks_mode]

'Programming > web 관련' 카테고리의 다른 글

chatGPT님 가라사대 Server-Sent Events (SSE)  (0) 2023.03.15
JWT 로그인 예제  (0) 2022.08.24
grid와 flex  (0) 2022.07.04
web gl on chrome  (0) 2021.12.14
markdown 문법 - 체크박스  (0) 2020.10.15
Posted by 구차니