잠시만 기다려 주세요

     '민주당 심판은 아직 끝나지 않았다.'
전체검색 :  
이번주 로또 및 연금번호 발생!!   |  HOME   |  여기는?   |  바다물때표   |  알림 (19)  |  여러가지 팁 (1095)  |  추천 및 재미 (163)  |  자료실 (28)  |  
시사, 이슈, 칼럼, 평론, 비평 (790)  |  끄적거림 (142)  |  문예 창작 (719)  |  바람 따라 (75)  |  시나리오 (760)  |  드라마 대본 (248)  |  
살인!


    golang

golang - URL Parsing, url 파싱하기. parse
이 름 : 바다아이   |   조회수 : 14494         짧은 주소 : https://www.bada-ie.com/su/?411591781223
// URLs provide a [uniform way to locate resources](http://adam.heroku.com/past/2010/3/30/urls_are_the_uniform_way_to_locate_resources/).
// Here's how to parse URLs in Go.

package main

import "fmt"
import "net"
import "net/url"

func main() {

    // We'll parse this example URL, which includes a
    // scheme, authentication info, host, port, path,
    // query params, and query fragment.
    s := "postgres://user:pass@host.com:5432/path?k=v#f"

    // Parse the URL and ensure there are no errors.
    u, err := url.Parse(s)
    if err != nil {
        panic(err)
    }

    // Accessing the scheme is straightforward.
    fmt.Println(u.Scheme)

    // `User` contains all authentication info; call
    // `Username` and `Password` on this for individual
    // values.
    fmt.Println(u.User)
    fmt.Println(u.User.Username())
    p, _ := u.User.Password()
    fmt.Println(p)

    // The `Host` contains both the hostname and the port,
    // if present. Use `SplitHostPort` to extract them.
    fmt.Println(u.Host)
    host, port, _ := net.SplitHostPort(u.Host)
    fmt.Println(host)
    fmt.Println(port)

    // Here we extract the `path` and the fragment after
    // the `#`.
    fmt.Println(u.Path)
    fmt.Println(u.Fragment)

    // To get query params in a string of `k=v` format,
    // use `RawQuery`. You can also parse query params
    // into a map. The parsed query param maps are from
    // strings to slices of strings, so index into `[0]`
    // if you only want the first value.
    fmt.Println(u.RawQuery)
    m, _ := url.ParseQuery(u.RawQuery)
    fmt.Println(m)
    fmt.Println(m["k"][0])
}


결과

postgres
user:pass
user
pass
host.com:5432
host.com
5432
/path
f
k=v
map[k:[v]]
v

출처 : https://gobyexample.com/url-parsing
| |





      1 page / 6 page
번 호 카테고리 제 목 이름 조회수
180 golang golang ... 바다아이 114
179 golang golang , ... 바다아이 2691
178 golang golang , map . 바다아이 2080
177 golang Golang (, , data ) , ... 바다아이 2393
176 golang golang sort ... 바다아이 2777
175 golang golang html.EscapeString html.UnescapeString input value ... 바다아이 2701
174 golang golang go.mod go.sum . GOPATH SRC not module, 1.16 . 바다아이 6218
173 golang go 1.16 ... is not in GOROOT.. GOPATH .... . 바다아이 7373
172 golang , String Formatting 바다아이 8691
171 golang rand.Intn , random, , . 바다아이 8214
170 golang golang ... 바다아이 11962
169 golang golang gopath, goroot .. golang 바다아이 8943
168 golang golang ... Force download file example 바다아이 10962
167 golang golang , , cpu, memory, disk 바다아이 12029
166 golang golang , ... GOOS, GOARCH 바다아이 9687
165 golang golang checkbox ... 바다아이 9543
164 golang golang , , http .... 바다아이 9368
163 golang golang nil , nil , nil ... 바다아이 9449
162 golang 2 golang, go , .... golang .... 바다아이 12691
161 golang golang postgresql, mysql, mariadb ... ` Grave () .. .. 바다아이 10003
160 golang golang postgresql mysql, mariadb scan , null .. 바다아이 10060
159 golang golang , iconv 바다아이 12879
158 golang golang quote escape, unquote 바다아이 10306
157 golang golang , http errorLog , , ... 바다아이 10691
156 golang golang interface , 바다아이 9767
155 golang golang struct .... 바다아이 10490
154 golang golang map map , 바다아이 9975
153 golang golang map .... .... 바다아이 9299
152 golang golang slice copy 바다아이 9489
151 golang golang goto 바다아이 10683
| |









Copyright ⓒ 2001.12. bada-ie.com. All rights reserved.
이 사이트는 리눅스에서 firefox 기준으로 작성되었습니다. 기타 브라우저에서는 다르게 보일 수 있습니다.
[ Ubuntu + GoLang + PostgreSQL + Mariadb ]
서버위치 : 오라클 클라우드 춘천  실행시간 : 0.24509
to webmaster... gogo sea. gogo sea.