This module is a pure Golang implementation to parse URIs with the scheme sip:
& sips:
. It tries to adhere to the spec in RFC-3261 19.1.1. It is meant to be small and efficent and require no libraries outside the standard lib.
Requires go 1.18+
go get github.com/percivalalb/sipuri
package main
import (
"fmt"
"github.com/percivalalb/sipuri"
)
func main() {
// Parse the URI. Errors on unexpected schemes or malformed URIs
sipURI, err := sipuri.Parse("sip:user:password@host:port;uri-parameters?headers")
if err != nil {
panic(err)
}
// Print the consistent components
fmt.Println(sipURI.User()) // user
fmt.Println(sipURI.Password()) // password
fmt.Println(sipURI.Host()) // host:port
fmt.Printf("%v\n", sipURI.Params()) // map[uri-parameters:[]]
fmt.Printf("%v\n", sipURI.Headers()) // map[headers:[]]
// Re-construct the URI
fmt.Println(sipURI.String()) // sip:user:password@host:port;uri-parameters=?headers=
}
The module should parse common sip:
& sips:
URIs, thought the module has yet to be thoroughly tested against outliers. Please report any issues, thanks!