什麼是URI,URL,URN?以及golang實現

URI

Uniform Resource Identifier

,統一資源標識符;

 

URL

Uniform Resource Locator

,統一資源定位符;

 

URN

Uniform Resource Name

,統一資源名稱。

 

其中,

URL,URN

URI

的子集。

URI

Uniform Resource Identifier

,統一資源標識符;

 

URL

Uniform Resource Locator

,統一資源定位符;

 

URN

Uniform Resource Name

,統一資源名稱。

 

其中,

URL,URN

URI

的子集。

URI

Uniform Resource Identifier

,統一資源標識符;

 

URL

Uniform Resource Locator

,統一資源定位符;

 

URN

Uniform Resource Name

,統一資源名稱。

 

其中,

URL,URN

URI

的子集。

URI

Uniform Resource Identifier

,統一資源標識符;

 

URL

Uniform Resource Locator

,統一資源定位符;

 

URN

Uniform Resource Name

,統一資源名稱。

 

其中,

URL,URN

URI

的子集。

1. 概念和關係

  • URI:Uniform Resource Identifier,即統一資源標誌符,用來唯一的標識一個資源

  • URL:Uniform Resource Locator,統一資源定位符。即URL可以用來標識一個資源。

  • URN:Uniform Resource Name,統一資源命名。即通過名字來表示資源的。

集中URL,URN是URI的一種實現方式。互聯網最廣泛使用的是URL

URI格式:[scheme:] scheme-specific-part

http://www.le.com

    mailto:[email protected]

 news:comp.go.lang

URI可以進一步分爲不透明的(opaque)和分層(hierarchical)的兩類

opaque指的是URI的scheme-specific-part部分不以/開頭,是一個整個部分,沒有分層結構。如:mailto:[email protected]news:comp.go.lang

hierarchical指的是以/開頭,scheme-specific-part可以由好幾部分組成


2. golang 對URI,URL實現

以斜槓開頭解析爲  :[scheme:][//[userinfo@]host][/]path[?query][#fragment]
否則解析爲(opaque):scheme:opaque[?query][#fragment]
type URL struct {
	Scheme     string
	Opaque     string    // encoded opaque data
	User       *Userinfo // username and password information
	Host       string    // host or host:port
	Path       string    // path (relative paths may omit leading slash)
	RawPath    string    // encoded path hint (see EscapedPath method)
	ForceQuery bool      // append a query ('?') even if RawQuery is empty
	RawQuery   string    // encoded query values, without '?'
	Fragment   string    // fragment for references, without '#'
}





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章