Learn Go Programming

Go, also known as Golang, is an open-source programming language developed by Google. It is designed for simplicity, efficiency, and strong performance.

Go is used in web development to build scalable applications and APIs, in cloud services to develop microservices, and in DevOps to develop automation tools. It’s also popular for networking servers and large-scale data processing tasks.

Many companies need developers who know Go, especially for backend, cloud, and DevOps roles.

Check out API guides on Go programming: Golang Standard Library (Learn 500+ in-built functions).

Go Tutorial

Go Control Flow Statements

Go Functions

Go Arrays and Strings

Go Packages and Modules

Go Types

Go Map

Go Error Handling

Go Concurrency

Go File Handling

Go Networking

Go Time

Go Programs with Output

Go Standard Library

Golang fmt Package Functions

The fmt package in Go provides formatting for input and output, offering a wide range of functions to handle strings, errors, and formatted I/O. Below is a list of commonly used functions in the fmt package:

FunctionDescription
Golang fmt.Append FunctionAppends a formatted string to a byte slice.
Golang fmt.Appendf FunctionWrites the formatted string to a specified writer with format specifiers.
Golang fmt.Appendln FunctionAppends a formatted string to a byte slice, followed by a newline.
Golang fmt.Errorf FunctionFormats according to a format specifier and returns a string as a value that satisfies the error interface.
Golang fmt.Sprintf FunctionFormats according to a format specifier and returns the resulting string.
Golang fmt.Fprint FunctionWrites the string to a specified writer, such as a file or an HTTP response.
Golang fmt.Fprintf FunctionIt reads from a specified reader and scans the input.
Golang fmt.Fprintln FunctionWrites the string to a specified writer, followed by a newline.
Golang fmt.Fscan FunctionReads from a specified reader, scanning the input.
Golang fmt.Fscanf FunctionReads from a specified reader, scanning the input with format specifiers.
Golang fmt.Fscanln FunctionReads from a specified reader, scanning the input until a newline.
Golang fmt.Print FunctionPrints the string to standard output.
Golang fmt.Printf FunctionPrints the formatted string to standard output, with format specifiers.
Golang fmt.Println FunctionPrints the string to standard output, followed by a newline.
Golang fmt.Scan FunctionReads from standard input, scanning the input.
Golang fmt.Scanf FunctionReads from standard input, scanning the input with format specifiers.
Golang fmt.Scanln FunctionReads from standard input, scanning the input until a newline.
Golang fmt.Sprint FunctionFormats using the default formats for its operands and returns the resulting string.
Golang fmt.Sprintf FunctionFormats according to a format specifier and returns the resulting string.
Golang fmt.Sprintln FunctionFormats using the default formats for its operands and returns the resulting string, followed by a newline.
Golang fmt.Sscan FunctionScans the string for the specified formats.
Golang fmt.Sscanf FunctionScans the string for the specified formats with format specifiers.
Golang fmt.Sscanln FunctionScans the string for the specified formats until a newline is encountered.

Golang strings Package Functions

The strings package in Go provides functions to manipulate UTF-8 encoded strings. It includes various utilities for searching, splitting, trimming, and formatting strings. Below is a list of commonly used functions in the strings package:

FunctionDescription
Golang strings.Clone FunctionReturns a newly allocated copy of the input string.
Golang strings.Compare FunctionCompares two strings lexicographically.
Golang strings.Contains FunctionChecks if a substring is within a string.
Golang strings.ContainsAny FunctionChecks if any of the characters in a string exist in another string.
Golang strings.ContainsFunc FunctionChecks if a string contains any characters satisfying a predicate function.
Golang strings.ContainsRune FunctionChecks if a rune is within a string.
Golang strings.Count FunctionCounts the number of non-overlapping instances of a substring in a string.
Golang strings.Cut FunctionSplits a string at the first occurrence of a substring and returns the two parts.
Golang strings.CutPrefix FunctionRemoves the provided prefix from a string.
Golang strings.CutSuffix FunctionRemoves the provided suffix from a string.
Golang strings.EqualFold FunctionCompares two strings for equality under Unicode case-folding.
Golang strings.Fields FunctionSplits a string into substrings at each instance of whitespace.
Golang strings.FieldsFunc FunctionSplits a string based on a custom function that determines where splits should occur.
Golang strings.Split FunctionSplits a string into substrings separated by a specified delimiter.
Golang strings.SplitAfter FunctionSplits a string into substrings after each instance of a specified delimiter.
Golang strings.SplitAfterN FunctionSplits a string into N substrings after each instance of a specified delimiter.
Golang strings.SplitN FunctionSplits a string into N substrings separated by a specified delimiter.
Golang strings.Title FunctionConverts a string to title case.
Golang strings.ToLower FunctionConverts all characters in a string to lowercase.
Golang strings.ToTitle FunctionConverts all characters in a string to title case.
Golang strings.ToUpper FunctionConverts all characters in a string to uppercase.
Golang strings.Trim FunctionRemoves all leading and trailing instances of specified characters from a string.
Golang strings.TrimFunc FunctionRemoves all leading and trailing instances of characters from a string based on a predicate function.
Golang strings.TrimLeft FunctionRemoves all leading instances of specified characters from a string.
Golang strings.TrimLeftFunc FunctionRemoves all leading instances of characters from a string based on a predicate function.
Golang strings.TrimPrefix FunctionRemoves a specified prefix from a string.
Golang strings.TrimRight FunctionRemoves all trailing instances of specified characters from a string.
Golang strings.TrimSpace FunctionRemoves all leading and trailing white space from a string.
Golang strings.TrimSuffix FunctionRemoves a specified suffix from a string.
Golang strings.Join FunctionJoins a slice of strings into a single string with a specified separator.
Golang strings.HasSuffix FunctionChecks if a string ends with a specified suffix.
Golang strings.HasPrefix FunctionChecks if a string starts with a specified prefix.
Golang strings.Index FunctionFinds the index of the first instance of a substring in a string.

Golang math Package Functions

The math package in Go provides basic constants and mathematical functions such as trigonometric, logarithmic, and exponential functions. Below is a list of commonly used functions in the math package:

FunctionDescription
Golang math.Abs FunctionReturns the absolute value of a given float number.
Golang math.Ceil FunctionReturns the smallest integer value greater than or equal to the input.
Golang math.Floor FunctionReturns the largest integer value less than or equal to the input.
Golang math.Trunc FunctionReturns the integer part of a float number, discarding the fractional part.
Golang math.Mod FunctionReturns the floating-point remainder of the division of two numbers.
Golang math.Modf FunctionReturns the fractional and integer parts of a floating-point number.
Golang math.Remainder FunctionComputes the remainder of the floating-point division of two numbers.
Golang math.Round FunctionRounds the floating-point number to the nearest integer, breaking ties by rounding away from zero.
Golang math.RoundToEven FunctionRounds the floating-point number to the nearest integer, breaking ties by rounding to the even number.
Golang math.Copysign FunctionReturns a number with the magnitude of the first argument and the sign of the second.
Golang math.Signbit FunctionChecks whether the sign of a floating-point number is negative.
Golang math.Dim FunctionComputes the positive difference between two numbers.
Golang math.Min FunctionReturns the smaller of two floating-point numbers.
Golang math.FMA FunctionComputes the fused multiply-add of three numbers.
Golang math.Exp FunctionReturns the exponential value of the input.
Golang math.Exp2 FunctionReturns the base-2 exponential value of the input.
Golang math.Expm1 FunctionReturns the value of (e^x – 1) of the input.
Golang math.Log FunctionReturns the natural logarithm of the input.
Golang math.Log10 FunctionReturns the base-10 logarithm of the input.
Golang math.Log1p FunctionReturns the natural logarithm of (1 + x) of the input.
Golang math.Log2 FunctionReturns the base-2 logarithm of the input.
Golang math.Logb FunctionReturns the exponent of the input number.
Golang math.Ilogb FunctionReturns the exponent of the input number as an integer.
Golang math.Pow FunctionReturns the base raised to the power of the exponent.
Golang math.Pow10 FunctionReturns the value of 10 raised to the power of the input.
Golang math.Sqrt FunctionReturns the square root of the input.
Golang math.Cbrt FunctionReturns the cube root of the input.
Golang math.Sin FunctionReturns the sine of the input angle.
Golang math.Cos FunctionReturns the cosine of the input angle.
Golang math.Tan FunctionReturns the tangent of the input angle.
Golang math.Asin FunctionReturns the arcsine of the input.
Golang math.Acos FunctionReturns the arccosine of the input.
Golang math.Atan FunctionReturns the arctangent of the input.
Golang math.Atan2 FunctionReturns the arctangent of y/x considering the sign of both arguments.
Golang math.Hypot FunctionReturns the square root of the sum of the squares of two inputs (the hypotenuse).
Golang math.Sincos FunctionComputes the sine and cosine of the input angle, returning both.
Golang math.Sinh FunctionReturns the hyperbolic sine of the input.
Golang math.Cosh FunctionReturns the hyperbolic cosine of the input.
Golang math.Asinh FunctionReturns the inverse hyperbolic sine of the input.
Golang math.Acosh FunctionReturns the inverse hyperbolic cosine of the input.
Golang math.Atanh FunctionReturns the inverse hyperbolic tangent of the input.
Golang math.Gamma FunctionComputes the Gamma function of the input.
Golang math.Lgamma FunctionReturns the natural logarithm of the absolute value of the Gamma function.
Golang math.Erf FunctionComputes the error function of the input.
Golang math.Erfc FunctionComputes the complementary error function of the input.
Golang math.Erfinv FunctionComputes the inverse of the error function.
Golang math.Erfcinv FunctionComputes the inverse of the complementary error function.
Golang math.Float32bits FunctionReturns the IEEE 754 binary representation of a 32-bit float as an unsigned integer.
Golang math.Float32frombits FunctionReturns the 32-bit float value corresponding to the given IEEE 754 binary representation.
Golang math.Float64bits FunctionReturns the IEEE 754 binary representation of a 64-bit float as an unsigned integer.
Golang math.IsInf FunctionChecks whether the input is an infinite number.
Golang math.IsNaN FunctionChecks whether the input is Not-a-Number (NaN).
Golang math.Nextafter FunctionReturns the next representable float value after x towards y.
Golang math.Nextafter32 FunctionReturns the next representable float value after x towards y for 32-bit floats.
Golang math.Frexp FunctionBreaks the floating-point number into a normalized fraction and an integral power of two.
Golang math.Ldexp FunctionComputes the value of x multiplied by 2 raised to the power of exp.

Golang math Package Functions

The math package in Go provides basic constants and mathematical functions such as trigonometric, logarithmic, and exponential functions. Below is a list of commonly used functions in the math package:

FunctionDescription
Golang math.Abs FunctionReturns the absolute value of a given float number.
Golang math.Ceil FunctionReturns the smallest integer value greater than or equal to the input.
Golang math.Floor FunctionReturns the largest integer value less than or equal to the input.
Golang math.Trunc FunctionReturns the integer part of a float number, discarding the fractional part.
Golang math.Mod FunctionReturns the floating-point remainder of the division of two numbers.
Golang math.Modf FunctionReturns the fractional and integer parts of a floating-point number.
Golang math.Remainder FunctionComputes the remainder of the floating-point division of two numbers.
Golang math.Round FunctionRounds the floating-point number to the nearest integer, breaking ties by rounding away from zero.
Golang math.RoundToEven FunctionRounds the floating-point number to the nearest integer, breaking ties by rounding to the even number.
Golang math.Copysign FunctionReturns a number with the magnitude of the first argument and the sign of the second.
Golang math.Signbit FunctionChecks whether the sign of a floating-point number is negative.
Golang math.Dim FunctionComputes the positive difference between two numbers.
Golang math.Min FunctionReturns the smaller of two floating-point numbers.
Golang math.FMA FunctionComputes the fused multiply-add of three numbers.
Golang math.Exp FunctionReturns the exponential value of the input.
Golang math.Exp2 FunctionReturns the base-2 exponential value of the input.
Golang math.Expm1 FunctionReturns the value of (e^x – 1) of the input.
Golang math.Log FunctionReturns the natural logarithm of the input.
Golang math.Log10 FunctionReturns the base-10 logarithm of the input.
Golang math.Log1p FunctionReturns the natural logarithm of (1 + x) of the input.
Golang math.Log2 FunctionReturns the base-2 logarithm of the input.
Golang math.Logb FunctionReturns the exponent of the input number.
Golang math.Ilogb FunctionReturns the exponent of the input number as an integer.
Golang math.Pow FunctionReturns the base raised to the power of the exponent.
Golang math.Pow10 FunctionReturns the value of 10 raised to the power of the input.
Golang math.Sqrt FunctionReturns the square root of the input.
Golang math.Cbrt FunctionReturns the cube root of the input.
Golang math.Sin FunctionReturns the sine of the input angle.
Golang math.Cos FunctionReturns the cosine of the input angle.
Golang math.Tan FunctionReturns the tangent of the input angle.
Golang math.Asin FunctionReturns the arcsine of the input.
Golang math.Acos FunctionReturns the arccosine of the input.
Golang math.Atan FunctionReturns the arctangent of the input.
Golang math.Atan2 FunctionReturns the arctangent of y/x considering the sign of both arguments.
Golang math.Hypot FunctionReturns the square root of the sum of the squares of two inputs (the hypotenuse).
Golang math.Sincos FunctionComputes the sine and cosine of the input angle, returning both.
Golang math.Sinh FunctionReturns the hyperbolic sine of the input.
Golang math.Cosh FunctionReturns the hyperbolic cosine of the input.
Golang math.Asinh FunctionReturns the inverse hyperbolic sine of the input.
Golang math.Acosh FunctionReturns the inverse hyperbolic cosine of the input.
Golang math.Atanh FunctionReturns the inverse hyperbolic tangent of the input.
Golang math.Gamma FunctionComputes the Gamma function of the input.
Golang math.Lgamma FunctionReturns the natural logarithm of the absolute value of the Gamma function.
Golang math.Erf FunctionComputes the error function of the input.
Golang math.Erfc FunctionComputes the complementary error function of the input.
Golang math.Erfinv FunctionComputes the inverse of the error function.
Golang math.Erfcinv FunctionComputes the inverse of the complementary error function.
Golang math.Float32bits FunctionReturns the IEEE 754 binary representation of a 32-bit float as an unsigned integer.
Golang math.Float32frombits FunctionReturns the 32-bit float value corresponding to the given IEEE 754 binary representation.
Golang math.Float64bits FunctionReturns the IEEE 754 binary representation of a 64-bit float as an unsigned integer.
Golang math.IsInf FunctionChecks whether the input is an infinite number.
Golang math.IsNaN FunctionChecks whether the input is Not-a-Number (NaN).
Golang math.Nextafter FunctionReturns the next representable float value after x towards y.
Golang math.Nextafter32 FunctionReturns the next representable float value after x towards y for 32-bit floats.
Golang math.Frexp FunctionBreaks the floating-point number into a normalized fraction and an integral power of two.
Golang math.Ldexp FunctionComputes the value of x multiplied by 2 raised to the power of exp.

Golang time Package Functions

The time package in Go provides functionality for measuring and displaying time. It includes functions for working with durations, time zones, formatting, and parsing time values. Below is a list of commonly used functions and methods in the time package:

Function/MethodDescription
Golang time.After FunctionReturns a channel that will receive the current time after at least the specified duration has passed.
Golang time.Sleep FunctionPauses the current goroutine for at least the specified duration.
Golang time.Tick FunctionReturns a channel that sends the time with a frequency specified by the duration.
Golang time.ParseDuration FunctionParses a duration string and returns the corresponding duration.
Golang time.Since FunctionReturns the time elapsed since the specified time.
Golang time.Until FunctionReturns the duration until the specified time.
Golang time.Duration.AbsReturns the absolute value of the duration.
Golang time.Duration.HoursReturns the duration as a floating-point number of hours.
Golang time.Duration.MicrosecondsReturns the duration as an integer number of microseconds.
Golang time.Duration.MillisecondsReturns the duration as an integer number of milliseconds.
Golang time.Duration.MinutesReturns the duration as a floating-point number of minutes.
Golang time.Duration.SecondsReturns the duration as a floating-point number of seconds.
Golang time.Duration.StringReturns a string representation of the duration.
Golang time.Duration.TruncateTruncates the duration to a multiple of another duration.
Golang time.FixedZone FunctionReturns a fixed time zone with a given name and offset in seconds.
Golang time.LoadLocation FunctionReturns the Location with the given name.
Golang time.LoadLocationFromTZData FunctionReturns a Location with the given name and timezone data.
Golang time.Location.StringReturns a string representation of the Location.
Golang time.ParseError.ErrorReturns the error string of the ParseError.
Golang time.Ticker.ResetResets the ticker to adjust its firing interval.
Golang time.Date FunctionReturns the Time corresponding to the specified date and time.
Golang time.Now FunctionReturns the current local time.
Golang time.Parse FunctionParses a formatted string and returns the corresponding Time.
Golang time.ParseInLocation FunctionParses a formatted string and returns the corresponding Time in the specified Location.
Golang time.Unix FunctionReturns the local time corresponding to the given Unix time.
Golang time.UnixMicro FunctionReturns the local time corresponding to the given Unix time in microseconds.
Golang time.UnixMilli FunctionReturns the local time corresponding to the given Unix time in milliseconds.
Golang time.Time.AddAdds the specified duration to the time and returns the result.
Golang time.Time.AddDateAdds the specified number of years, months, and days to the time and returns the result.
Golang time.Time.AfterReturns true if the time is after the specified time.
Golang time.Time.AppendFormatAppends the formatted time to a byte slice and returns the result.
Golang time.Time.BeforeReturns true if the time is before the specified time.
Golang time.Time.ClockReturns the hour, minute, and second of the time.
Golang time.Time.DateReturns the year, month, and day of the time.
Golang time.Time.DayReturns the day of the month.
Golang time.Time.EqualReports whether the time is equal to the specified time.
Golang time.Time.GoStringReturns a string representation of the time.
Golang time.Time.HourReturns the hour within the day of the time.
Golang time.Time.InReturns the time in the specified location.
Golang time.Time.LocalReturns the time in the local location.
Golang time.Time.LocationReturns the time’s location information.
Golang time.Time.MarshalJSONReturns the JSON encoding of the time.
Golang time.Time.MinuteReturns the minute within the hour of the time.
Golang time.Time.MonthReturns the month of the time.
Golang time.Time.NanosecondReturns the nanosecond within the second of the time.
Golang time.Time.SecondReturns the second within the minute of the time.
Golang time.Time.StringReturns a string representation of the time.
Golang time.Time.SubReturns the duration between two times.
Golang time.Time.TruncateTruncates the time to a multiple of a duration.
Golang time.Time.UTCReturns the UTC time corresponding to the local time.
Golang time.Time.WeekdayReturns the day of the week specified by the time.
Golang time.Time.YearReturns the year of the time.
Golang time.Time.ZoneReturns the time zone abbreviation and offset in seconds east of UTC.
Golang time.AfterFunc FunctionWaits for the duration to elapse and then calls the provided function.
Golang time.NewTimer FunctionCreates a new Timer that will send the current time on its channel after at least the specified duration has passed.
Golang time.Timer.ResetResets the timer to its original duration.
Golang time.Timer.StopStops the timer from sending any more events.

Golang bytes Package Functions

The bytes package in Go provides a variety of functions for manipulating byte slices. These functions are useful for searching, modifying, and comparing byte slices. Below is a list of commonly used functions in the bytes package:

FunctionDescription
Golang bytes.Clone FunctionReturns a copy of the given byte slice.
Golang bytes.Compare FunctionCompares two byte slices lexicographically.
Golang bytes.Contains FunctionChecks whether a byte slice contains another byte slice.
Golang bytes.ContainsAny FunctionReports whether any of the bytes in the second slice are in the first slice.
Golang bytes.ContainsFunc FunctionReports whether any byte in the slice satisfies the provided function.
Golang bytes.ContainsRune FunctionReports whether the byte slice contains the given rune.
Golang bytes.Count FunctionCounts the number of non-overlapping instances of a sub-slice in a slice.
Golang bytes.Cut FunctionSplits a slice into two around the first instance of a separator.
Golang bytes.CutPrefix FunctionRemoves the provided prefix from a byte slice.
Golang bytes.CutSuffix FunctionRemoves the provided suffix from a byte slice.
Golang bytes.Equal FunctionChecks if two byte slices are equal.
Golang bytes.EqualFold FunctionPerforms a case-insensitive comparison of two byte slices.
Golang bytes.Fields FunctionSplits the byte slice around each instance of one or more consecutive white space characters.
Golang bytes.FieldsFunc FunctionSplits the byte slice around each instance of a byte that satisfies the provided function.
Golang bytes.Split FunctionSplits a byte slice into all substrings separated by a separator and returns a slice of the substrings.
Golang bytes.SplitAfter FunctionSplits a byte slice after each instance of a separator and returns a slice of the substrings.
Golang bytes.HasPrefix FunctionChecks whether the byte slice begins with the specified prefix.
Golang bytes.HasSuffix FunctionChecks whether the byte slice ends with the specified suffix.
Golang bytes.Index FunctionFinds the first instance of a byte slice in another byte slice.
Golang bytes.IndexAny FunctionFinds the first instance of any byte from the second slice in the first slice.
Golang bytes.IndexByte FunctionFinds the first instance of the byte in the slice.
Golang bytes.IndexFunc FunctionFinds the first byte in the slice that satisfies the provided function.
Golang bytes.LastIndex FunctionFinds the last instance of a byte slice in another byte slice.
Golang bytes.LastIndexByte FunctionFinds the last instance of the byte in the slice.
Golang bytes.Map FunctionApplies a transformation function to each byte in the slice.
Golang bytes.Repeat FunctionReturns a new byte slice consisting of the specified number of copies of the original byte slice.
Golang bytes.Replace FunctionReturns a copy of the slice with all non-overlapping instances of the old slice replaced by the new slice.
Golang bytes.ReplaceAll FunctionReturns a copy of the slice with all instances of the old slice replaced by the new slice.
Golang bytes.Runes FunctionConverts the byte slice into a slice of runes (Unicode code points).
Golang bytes.Title FunctionConverts the byte slice to title case.
Golang bytes.ToLower FunctionConverts all the characters in the byte slice to lowercase.
Golang bytes.ToUpper FunctionConverts all the characters in the byte slice to uppercase.
Golang bytes.Trim FunctionTrims the leading and trailing bytes contained in the cutset from the slice.
Golang bytes.TrimFunc FunctionTrims the leading and trailing bytes that satisfy the provided function.
Golang bytes.TrimLeft FunctionTrims the leading bytes contained in the cutset from the slice.
Golang bytes.TrimPrefix FunctionRemoves the specified prefix from the byte slice.
Golang bytes.TrimRight FunctionTrims the trailing bytes contained in the cutset from the slice.
Golang bytes.TrimSpace FunctionTrims all leading and trailing white space characters from the byte slice.
Golang bytes.NewBuffer FunctionCreates and returns a new buffer using the provided byte slice.
Golang bytes.NewBufferString FunctionCreates and returns a new buffer using the provided string.

Golang http Package Functions

The http package in Go is a powerful tool for building web servers and handling HTTP requests and responses. It provides a wide range of functions that help in managing HTTP connections, serving content, and processing requests. Below is a list of commonly used functions in the http package:

FunctionDescription
Golang http.HandleFunc FunctionRegisters a function to handle requests for a given pattern.
Golang http.ListenAndServe FunctionStarts an HTTP server on a given address and serves incoming requests.
Golang http.ListenAndServeTLS FunctionStarts an HTTPS server with TLS on a given address and serves incoming requests.
Golang http.Serve FunctionAccepts incoming connections on a listener and serves HTTP requests.
Golang http.ServeTLS FunctionAccepts incoming TLS connections on a listener and serves HTTPS requests.
Golang http.ServeFile FunctionServes a file from the server’s file system to the client.
Golang http.ServeContent FunctionServes content from an io.ReadSeeker object, such as a file, to the client.
Golang http.Redirect FunctionRedirects the client to a different URL.
Golang http.Error FunctionSends an error response to the client.
Golang http.NotFound FunctionSends a 404 Not Found response to the client.
Golang http.NotFoundHandler FunctionReturns a handler that responds with a 404 Not Found.
Golang http.RedirectHandler FunctionReturns a handler that redirects the client to a different URL.
Golang http.StripPrefix FunctionReturns a handler that serves HTTP requests by removing the given prefix from the request URL’s path.
Golang http.TimeoutHandler FunctionReturns a handler that adds a timeout to another handler.
Golang http.MaxBytesReader FunctionWraps an io.ReadCloser to enforce a maximum read limit.
Golang http.NewRequest FunctionCreates a new HTTP request with the given method, URL, and optional body.
Golang http.ReadResponse FunctionReads and returns an HTTP response from a buffered reader.
Golang http.NewRequestWithContext FunctionCreates a new HTTP request with a context.
Golang http.Get FunctionSends an HTTP GET request to the specified URL.
Golang http.Post FunctionSends an HTTP POST request to the specified URL.
Golang http.PostForm FunctionSends an HTTP POST request with form data.
Golang http.ParseFormParses the raw query and updates the provided values.

Golang url Package Functions

The url package in Go is used for parsing and manipulating URLs. It provides functions for URL parsing, encoding, and constructing query parameters, making it essential for web development. Below is a list of commonly used functions in the url package:

FunctionDescription
Golang url.Parse FunctionParses a URL string and returns a URL structure.
Golang url.QueryEscape FunctionEscapes a string so it can be safely placed in a URL query.
Golang url.ParseRequestURI FunctionParses a URL and ensures it is a valid RequestURI.
Golang url.QueryUnescape FunctionUnescapes a URL query string.
Golang url.PathEscape FunctionEscapes a string for safe inclusion in a URL path segment.
Golang url.PathUnescape FunctionUnescapes a URL path string.
Golang url.URL.StringReturns the string representation of a URL.
Golang url.URL.QueryReturns the query parameters of a URL as a Values structure.
Golang url.URL.ResolveReferenceResolves a reference URL against a base URL.
Golang url.URL.HostnameReturns the hostname of a URL.
Golang url.URL.PortReturns the port of a URL, if specified.
Golang url.URL.IsAbsReturns whether the URL is absolute.
Golang url.URL.RequestURIReturns the request URI of the URL.
Golang url.URL.EscapedPathReturns the escaped path of the URL.
Golang url.User FunctionReturns a Userinfo structure with a username set.
Golang url.UserPassword FunctionReturns a Userinfo structure with a username and password set.
Golang url.Values.EncodeEncodes the values into a URL-encoded query string.
Golang url.Values.GetGets the first value associated with the given key.
Golang url.Values.SetSets the key to the given value, replacing any existing values.
Golang url.Values.AddAdds the value to the key, appending to any existing values.
Golang url.URL.JoinPathJoins path elements to the URL’s path.
Golang url.Values.HasChecks if the key exists in the values.

Golang os Package Functions

The os package in Go provides a platform-independent interface to operating system functionality, including file handling, process management, and environment variables. Here is a list of commonly used functions and methods in the os package:

Function/MethodDescription
Golang os.Chdir FunctionChanges the current working directory to the specified path.
Golang os.Chmod FunctionChanges the mode (permissions) of a file.
Golang os.Chown FunctionChanges the owner and group IDs of a file.
Golang os.Chtimes FunctionChanges the access and modification times of a file.
Golang os.DirFS FunctionReturns a file system rooted at the specified directory.
Golang os.Environ FunctionReturns a copy of strings representing the environment variables.
Golang os.Executable FunctionReturns the path name for the executable that started the current process.
Golang os.Exit FunctionExits the program with the specified status code.
Golang os.Expand FunctionReplaces ${var} or $var in a string based on the mapping function provided.
Golang os.ExpandEnv FunctionReplaces ${var} or $var in a string using the environment variables.
Golang os.Getegid FunctionReturns the effective group ID of the calling process.
Golang os.Getenv FunctionRetrieves the value of the environment variable named by the key.
Golang os.Geteuid FunctionReturns the effective user ID of the calling process.
Golang os.Getgid FunctionReturns the group ID of the calling process.
Golang os.Getgroups FunctionReturns a list of the group IDs of the calling process.
Golang os.Getpagesize FunctionReturns the underlying system’s memory page size.
Golang os.Getpid FunctionReturns the process ID of the calling process.
Golang os.Getppid FunctionReturns the parent process ID of the calling process.
Golang os.Getuid FunctionReturns the user ID of the calling process.
Golang os.Getwd FunctionReturns a rooted path name corresponding to the current working directory.
Golang os.Hostname FunctionReturns the host name reported by the kernel.
Golang os.IsExist FunctionReturns true if the error indicates that a file or directory already exists.
Golang os.IsNotExist FunctionReturns true if the error indicates that a file or directory does not exist.
Golang os.IsPathSeparator FunctionReturns true if the character is a directory separator.
Golang os.IsPermission FunctionReturns true if the error indicates a permission problem.
Golang os.IsTimeout FunctionReturns true if the error indicates a timeout.
Golang os.LookupEnv FunctionRetrieves the value of the environment variable named by the key, and returns whether the key was present.
Golang os.Mkdir FunctionCreates a new directory with the specified name and permission bits.
Golang os.MkdirAll FunctionCreates a directory named path, along with any necessary parents.
Golang os.MkdirTemp FunctionCreates a new temporary directory in the specified directory.
Golang os.Pipe FunctionReturns a connected pair of Files; reads from r return bytes written to w.
Golang os.ReadFile FunctionReads the contents of the named file and returns it as a byte slice.
Golang os.Remove FunctionRemoves the named file or directory.
Golang os.RemoveAll FunctionRemoves the named file or directory and any children it contains.
Golang os.Rename FunctionRenames a file or directory.
Golang os.SameFile FunctionReports whether two files describe the same file system entity.
Golang os.TempDir FunctionReturns the default directory to use for temporary files.
Golang os.Truncate FunctionTruncates a file to a specified length.
Golang os.Unsetenv FunctionDeletes the environment variable named by the key.
Golang os.UserHomeDir FunctionReturns the current user’s home directory.
Golang os.WriteFile FunctionWrites data to a file named by filename.
Golang os.Create FunctionCreates the named file with mode 0666 (before umask) and opens it for writing.
Golang os.CreateTemp FunctionCreates a new temporary file in the specified directory, opening it for reading and writing.
Golang os.NewFile FunctionReturns a new File for the given file descriptor.
Golang os.Open FunctionOpens the named file for reading.
Golang os.OpenFile FunctionOpens the named file with the specified flag and perm, if applicable.
Golang os.File.ChdirChanges the current working directory to the file.
Golang os.File.ChmodChanges the mode (permissions) of the file.
Golang os.File.ChownChanges the owner and group IDs of the file.
Golang os.File.CloseCloses the file, rendering it unusable for I/O.
Golang os.File.FdReturns the integer Unix file descriptor referencing the open file.
Golang os.File.NameReturns the name of the file as presented to Open.
Golang os.File.ReadReads up to len(b) bytes from the file.
Golang os.File.ReadDirReads the contents of the directory associated with the file.
Golang os.File.ReadFromReads data from r until EOF and writes it to the file.
Golang os.File.StatReturns a FileInfo describing the file.
Golang os.File.TruncateTruncates the file to a specified length.
Golang os.File.WriteWrites len(b) bytes to the file.
Golang os.File.WriteAtWrites len(b) bytes to the file starting at byte offset off.
Golang os.File.WriteStringWrites the contents of the string s to the file.
Golang os.Stat FunctionReturns a `FileInfo` describing the named file.
Golang os.FindProcess FunctionFinds the process with the given process ID, returning a `Process` struct.
Golang os.StartProcess FunctionStarts a new process with the given program name and arguments.
Golang os.Process.KillTerminates the process by sending the `SIGKILL` signal.

Golang JSON Package Functions

The encoding/json package in Go provides functions for working with JSON data, including marshalling and unmarshalling of data structures. Here is a list of commonly used functions in the json package:

FunctionDescription
Golang json.Marshal FunctionEncodes a Go data structure into JSON format.
Golang json.MarshalIndent FunctionEncodes a Go data structure into JSON format with indentation for better readability.
Golang json.Unmarshal FunctionDecodes JSON data into a Go data structure.
Golang json.NewDecoder FunctionCreates a new JSON decoder that reads from an input stream.
Golang json.NewEncoder FunctionCreates a new JSON encoder that writes to an output stream.
Golang json.Compact FunctionRemoves insignificant space characters from JSON data.
Golang json.Indent FunctionFormats JSON data with indentation for better readability.
Golang json.Valid FunctionChecks if a byte slice is valid JSON.
Golang json.RawMessage TypeRepresents a raw encoded JSON value to delay JSON decoding or precompute a JSON encoding.

Golang Log Package Functions

The log package in Go provides simple logging capabilities, including functions for printing, formatting, and writing log messages. Here is a list of commonly used functions in the log package:

FunctionDescription
Golang log.Fatal FunctionLogs a message and then calls os.Exit(1).
Golang log.Fatalf FunctionFormats a message according to a format specifier and logs it, then calls os.Exit(1).
Golang log.Fatalln FunctionLogs a message with a newline and then calls os.Exit(1).
Golang log.Panic FunctionLogs a message and then calls panic.
Golang log.Panicf FunctionFormats a message according to a format specifier and logs it, then calls panic.
Golang log.Panicln FunctionLogs a message with a newline and then calls panic.
Golang log.Print FunctionLogs a message.
Golang log.Printf FunctionFormats a message according to a format specifier and logs it.
Golang log.Println FunctionLogs a message with a newline.
Golang log.SetPrefix FunctionSets the prefix for log messages.
Golang log.SetOutput FunctionSets the output destination for log messages.
Golang log.Writer FunctionReturns the output destination for log messages.
Golang log.Prefix FunctionReturns the prefix for log messages.
Golang log.Output FunctionLogs a message to the specified output with a given number of stack frames to skip.

Golang strconv Package Functions

The strconv package in Go provides functions for converting between strings and other data types, such as integers and floating-point numbers. It also includes functions for quoting and unquoting string literals. Below is a list of commonly used functions in the strconv package:

FunctionDescription
Golang strconv.AppendBool FunctionAppends the string form of the boolean to the destination byte slice.
Golang strconv.AppendFloat FunctionAppends the string form of the floating-point number to the destination byte slice.
Golang strconv.AppendInt FunctionAppends the string form of the integer to the destination byte slice.
Golang strconv.AppendUint FunctionAppends the string form of the unsigned integer to the destination byte slice.
Golang strconv.Atoi FunctionConverts a string to an integer.
Golang strconv.FormatBool FunctionReturns the string representation of a boolean value.
Golang strconv.FormatComplex FunctionReturns the string representation of a complex number.
Golang strconv.FormatFloat FunctionReturns the string representation of a floating-point number.
Golang strconv.FormatInt FunctionReturns the string representation of an integer.
Golang strconv.FormatUint FunctionReturns the string representation of an unsigned integer.
Golang strconv.ParseComplex FunctionParses a string as a complex number.
Golang strconv.ParseFloat FunctionParses a string as a floating-point number.
Golang strconv.ParseInt FunctionParses a string as an integer.
Golang strconv.Itoa FunctionConverts an integer to its string representation.
Golang strconv.AppendQuote FunctionAppends a double-quoted Go string literal representing s to dst and returns the extended buffer.
Golang strconv.AppendQuoteRune FunctionAppends a single-quoted Go character literal representing the rune to dst and returns the extended buffer.
Golang strconv.Quote FunctionReturns a double-quoted Go string literal representing s.
Golang strconv.QuoteToASCII FunctionReturns a double-quoted Go string literal representing s, safely escaped with ASCII only.
Golang strconv.QuotedPrefix FunctionScans the beginning of s for a string literal prefix. The prefix may be single, double, or back quotes.
Golang strconv.UnquoteChar FunctionUnquotes a single character, reporting the character’s value and its size.

Golang slices Package Functions

The slices package in Go provides a variety of utility functions to work with slices. These functions include operations such as searching, sorting, comparing, and modifying slices. Below is a list of commonly used functions in the slices package:

FunctionDescription
Golang slices.BinarySearch FunctionPerforms a binary search on a sorted slice and returns the position of the target element.
Golang slices.BinarySearchFunc FunctionPerforms a binary search on a sorted slice using a custom comparison function.
Golang slices.Clip FunctionReturns a slice with the same elements as the original, but with a smaller capacity.
Golang slices.Clone FunctionCreates a copy of the slice with a new underlying array.
Golang slices.Compact FunctionRemoves adjacent duplicates from a slice.
Golang slices.CompactFunc FunctionRemoves adjacent duplicates from a slice using a custom comparison function.
Golang slices.Compare FunctionCompares two slices lexicographically.
Golang slices.CompareFunc FunctionCompares two slices lexicographically using a custom comparison function.
Golang slices.Concat FunctionConcatenates multiple slices into a single slice.
Golang slices.ContainsFunc FunctionChecks if any element in the slice satisfies the provided predicate function.
Golang slices.Delete FunctionDeletes elements from a slice between specified indices.
Golang slices.DeleteFunc FunctionDeletes elements from a slice that satisfy the provided predicate function.
Golang slices.Equal FunctionChecks if two slices are equal.
Golang slices.EqualFunc FunctionChecks if two slices are equal using a custom comparison function.
Golang slices.Grow FunctionGrows the capacity of the slice.
Golang slices.Index FunctionFinds the first index of the target element in the slice.
Golang slices.IndexFunc FunctionFinds the first index of an element in the slice that satisfies the provided predicate function.
Golang slices.Insert FunctionInserts elements into the slice at the specified index.
Golang slices.IsSorted FunctionChecks if the slice is sorted.
Golang slices.IsSortedFunc FunctionChecks if the slice is sorted using a custom comparison function.
Golang slices.Max FunctionFinds the maximum value in the slice.
Golang slices.MaxFunc FunctionFinds the maximum value in the slice using a custom comparison function.
Golang slices.Min FunctionFinds the minimum value in the slice.
Golang slices.MinFunc FunctionFinds the minimum value in the slice using a custom comparison function.
Golang slices.Replace FunctionReplaces elements in a slice between specified indices with elements from another slice.
Golang slices.Reverse FunctionReverses the elements of the slice.
Golang slices.Sort FunctionSorts the elements of the slice.
Golang slices.SortFunc FunctionSorts the elements of the slice using a custom comparison function.
Golang slices.SortStableFunc FunctionSorts the elements of the slice using a custom comparison function, maintaining the order of equal elements.

Golang sort Package Functions

The sort package in Go provides a collection of functions for sorting and searching slices and arrays. These functions cover a variety of data types, including integers, floating-point numbers, and strings. Below is a list of commonly used functions in the sort package:

FunctionDescription
Golang sort.Find FunctionFinds an index of the first occurrence of an element in a sorted slice.
Golang sort.Float64s FunctionSorts a slice of float64s in increasing order.
Golang sort.Float64sAreSorted FunctionReports whether a slice of float64s is sorted in increasing order.
Golang sort.Ints FunctionSorts a slice of ints in increasing order.
Golang sort.IntsAreSorted FunctionReports whether a slice of ints is sorted in increasing order.
Golang sort.IsSorted FunctionReports whether the data is sorted.
Golang sort.Search FunctionSearches for the index where a value should be inserted in a sorted slice.
Golang sort.SearchFloat64s FunctionSearches for a value in a sorted slice of float64s and returns its index.
Golang sort.SearchInts FunctionSearches for a value in a sorted slice of ints and returns its index.
Golang sort.SearchStrings FunctionSearches for a value in a sorted slice of strings and returns its index.
Golang sort.Slice FunctionSorts a slice according to a provided comparison function.
Golang sort.SliceIsSorted FunctionReports whether a slice is sorted according to a provided comparison function.
Golang sort.Sort FunctionSorts data according to a provided interface.
Golang sort.Strings FunctionSorts a slice of strings in increasing order.

Golang unicode Package Functions

The unicode package in Go offers a variety of functions to work with Unicode characters, providing tools to test, convert, and classify them. Below is a list of commonly used functions in the unicode package:

FunctionDescription
Golang unicode.In FunctionChecks if a character belongs to one or more ranges of Unicode code points.
Golang unicode.Is FunctionDetermines if a character belongs to a specific Unicode property.
Golang unicode.IsDigit FunctionReports whether the rune is a decimal digit.
Golang unicode.IsLetter FunctionChecks if a character is a letter.
Golang unicode.IsLower FunctionDetermines if a character is a lowercase letter.
Golang unicode.IsOneOf FunctionChecks if a character belongs to one of a set of ranges.
Golang unicode.IsPrint FunctionReports whether the rune is defined as printable.
Golang unicode.IsPunct FunctionReports whether the rune is a Unicode punctuation character.
Golang unicode.IsSpace FunctionChecks if a character is a white space.
Golang unicode.IsTitle FunctionDetermines if a character is a title case letter.
Golang unicode.IsUpper FunctionReports whether the rune is an uppercase letter.
Golang unicode.To FunctionMaps the rune to another rune, typically for case conversion.
Golang unicode.ToLower FunctionConverts the rune to lowercase.
Golang unicode.ToUpper FunctionConverts the rune to uppercase.

Golang regexp Package Functions

The regexp package in Go provides support for regular expressions, enabling pattern matching in strings. Here is a list of commonly used functions in the regexp package:

FunctionDescription
Golang regexp.Compile FunctionParses a regular expression and returns, if successful, a Regexp object that can be used to match against text.
Golang regexp.CompilePOSIX FunctionCompiles a regular expression in POSIX syntax and returns a Regexp object that can be used to match against text.
Golang regexp.MustCompile FunctionCompiles a regular expression, panicking if the expression is invalid. It returns a Regexp object that can be used to match against text.
Golang regexp.Match FunctionMatches a string against a regular expression pattern and returns a boolean indicating whether it matches.
Golang regexp.MatchReader FunctionMatches the text read from an io.Reader against a regular expression pattern and returns a boolean indicating whether it matches.
Golang regexp.MatchReader FunctionMatches the text read from an io.Reader against a regular expression pattern and returns a boolean indicating whether it matches.

Golang regexp Package Functions

The regexp package in Go provides support for regular expressions, enabling pattern matching in strings. Here is a list of commonly used functions in the regexp package:

FunctionDescription
Golang regexp.Compile FunctionParses a regular expression and returns, if successful, a Regexp object that can be used to match against text.
Golang regexp.CompilePOSIX FunctionCompiles a regular expression in POSIX syntax and returns a Regexp object that can be used to match against text.
Golang regexp.MustCompile FunctionCompiles a regular expression, panicking if the expression is invalid. It returns a Regexp object that can be used to match against text.
Golang regexp.Match FunctionMatches a string against a regular expression pattern and returns a boolean indicating whether it matches.
Golang regexp.MatchReader FunctionMatches the text read from an io.Reader against a regular expression pattern and returns a boolean indicating whether it matches.
Golang regexp.MatchReader FunctionMatches the text read from an io.Reader against a regular expression pattern and returns a boolean indicating whether it matches.

Golang filepath Package Functions

The filepath package in Go provides utilities for manipulating filename paths in a way that is portable between operating systems. Below is a list of commonly used functions in the filepath package:

FunctionDescription
Golang filepath.Abs FunctionReturns an absolute representation of a given path.
Golang filepath.Base FunctionReturns the last element of a given path.
Golang filepath.Clean FunctionReturns the shortest path name equivalent to the given path by eliminating redundant elements.
Golang filepath.Dir FunctionReturns all but the last element of the given path, typically the path’s directory.
Golang filepath.FromSlash FunctionConverts forward slashes in a path to the system’s path separator.
Golang filepath.Join FunctionJoins any number of path elements into a single path, adding separators as necessary.
Golang filepath.Rel FunctionComputes a relative path that is equivalent to the target path when joined to the base path.
Golang filepath.Split FunctionSplits a path into a directory and file name component.
Golang filepath.ToSlash FunctionConverts the system’s path separator to forward slashes in a given path.
Golang filepath.VolumeName FunctionReturns the leading volume name of the given path, such as “C:” for Windows.
Golang filepath.Glob FunctionReturns the names of all files matching the given pattern.
Golang filepath.Walk FunctionWalks the file tree rooted at the specified directory, calling a function for each file or directory found.
Golang filepath.WalkDir FunctionWalks the file tree rooted at the specified directory, similar to Walk, but with an additional context.
Golang filepath.SkipDir FunctionSkips the remaining files in the current directory during a walk.
Golang filepath.IsAbs FunctionReports whether the path is absolute.

Golang reflect Package Functions

The reflect package in Go is used for runtime reflection, allowing you to inspect and manipulate objects and types dynamically. Here is a list of commonly used functions in the reflect package:

FunctionDescription
Golang reflect.TypeOf FunctionReturns the reflection Type that represents the dynamic type of the interface.
Golang reflect.ValueOf FunctionReturns a new Value initialized to the concrete value stored in the interface.
Golang reflect.Zero FunctionReturns a Value representing the zero value for the specified type.
Golang reflect.New FunctionReturns a Value representing a pointer to a new zero value for the specified type.
Golang reflect.MakeSlice FunctionCreates a new slice value for the specified type, length, and capacity.
Golang reflect.MakeMap FunctionCreates a new map value for the specified type.
Golang reflect.MakeChan FunctionCreates a new channel value for the specified type and buffer size.
Golang reflect.MakeFunc FunctionCreates a new function value with the specified Type that executes the provided function implementation.
Golang reflect.Indirect FunctionReturns the value that a pointer or interface value points to.
Golang reflect.DeepEqual FunctionCompares two values deeply for equality.
Golang reflect.ArrayOf FunctionReturns the Type representing a fixed-size array of the specified length and element type.
Golang reflect.ChanOf FunctionReturns the Type representing a channel with the specified direction and element type.
Golang reflect.InterfaceOf FunctionReturns the Type representing an interface with the specified methods.
Golang reflect.MapOf FunctionReturns the Type representing a map with the specified key and element types.
Golang reflect.PtrTo FunctionReturns the Type representing a pointer to the specified type.
Golang reflect.SliceOf FunctionReturns the Type representing a slice with the specified element type.
Golang reflect.StructOf FunctionReturns the Type representing a struct with the specified fields.

Scroll to Top