u, _ := url.Parse("https://example.com/path/to/page#my-fragment") fragment := u.Fragment fmt.Println(fragment) // Output: my-fragment
u, _ := url.Parse("https://example.com/path/to/page#old-fragment") u.Fragment = "new-fragment" fmt.Println(u.String()) // Output: https://example.com/path/to/page#new-fragmentIn both examples, the `Fragment` field is used to get or set the fragment of a URL. The net/url package provides convenient methods for parsing and manipulating URLs, making it a useful library for working with web resources.