Standard library / net/url

url.UserPassword()

Create user information with a password; avoid embedding real credentials in URLs. Expected stdout: 'demo true\n'.

Formal Syntax & Structure

go syntaxgo
func UserPassword(username, password string) *Userinfo

Parameters & Attributes

NameTypeDescription
usernamestringSynthetic or actual account name.
passwordstringPassword; never log real credentials.

Return Value

*Userinfo

Operation result; check errors and validity indicators when returned.

Working Example

Example Snippetgo
package main
import (  "fmt"  "net/url")
func main() {  u := url.UserPassword("demo", "test-only")  _, ok := u.Password()  fmt.Println(u.Username(), ok)}
func must[T any](v T, e error) T {  if e != nil {    panic(e)  }  return v}func check(e error) {  if e != nil {    panic(e)  }}
Go Reference