Every request starts from a URL, and the very first thing a client reads off it is the scheme - http or https - which decides how to talk to the far end. Today you build the smallest possible URL parser, one that pulls just the scheme, so the type every later lesson thickens exists from day one.
Parse a URL string into a value whose scheme field holds the lowercased scheme.
A URL is the address a client aims at, and its first component is the
scheme: the http or https before the ://. The scheme is the single most
important thing about a URL because it decides everything downstream - which
default port to use, whether the connection is encrypted, how the request is
framed. So the parser earns its keep by reading the scheme first.
Schemes are case-insensitive, so HTTP, Http, and http all mean the same
thing; the convention is to store them lowercased so later comparisons are simple
equality checks. Keep the type small today - a struct with one filled field and
room for the rest. Everything else about the URL arrives one lesson at a time on
top of this.
// the whole client will grow around this typetype URL struct {Scheme string// Host, Port, Path, Query, Fragment arrive over the next lessons}// the scheme is everything before the first "://", lowercasedfunc Parse(raw string) (*URL, error) {// split on "://", lowercase the left half}