{"id":473,"date":"2026-06-05T09:00:00","date_gmt":"2026-06-05T03:30:00","guid":{"rendered":"https:\/\/smitabharat.com\/blog\/go-functional-options-pattern\/"},"modified":"2026-06-05T09:00:00","modified_gmt":"2026-06-05T03:30:00","slug":"go-functional-options-pattern","status":"publish","type":"post","link":"https:\/\/smitabharat.com\/blog\/go-functional-options-pattern\/","title":{"rendered":"Go Functional Options Pattern Explained Simply"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Go functional options are a clean way to build objects that have many settings. In this post, you will learn why long constructors become painful and how options fix that. Then we will build a small server type with safe defaults and optional settings.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This lesson builds on <a href=\"https:\/\/smitabharat.com\/blog\/go-functions-beginners-guide\/\">Go functions<\/a> and <a href=\"https:\/\/smitabharat.com\/blog\/go-closures-anonymous-functions\/\">Go closures<\/a>. We also use ideas from <a href=\"https:\/\/smitabharat.com\/blog\/go-structs-beginners-guide\/\">Go structs<\/a> and <a href=\"https:\/\/smitabharat.com\/blog\/go-error-wrapping-guide\/\">Go error wrapping<\/a>. So it helps to read those first.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Are Go Functional Options?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Suppose you write a <code>NewServer<\/code> function. At first, it takes one argument, which is the address. Then someone wants a port, so you add a second argument. Next comes a timeout, then a TLS flag, then a logger. Soon, the call looks like <code>NewServer(\"localhost\", 8080, 30, true, nil)<\/code>, and nobody knows what each value means.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Go functional options solve this problem. Instead of many arguments, the constructor takes the one required value plus any number of small option functions. Each option changes one setting, so you pass only the options you care about.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of ordering a coffee. You say &#8220;a large latte&#8221; and then you add &#8220;with oat milk&#8221; and &#8220;extra hot&#8221;. You do not fill in a form with twenty boxes. In the same way, Go functional options let you name just the changes you want, and nothing else.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Go Functional Options Matter<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Go has no default arguments and no function overloading. Because of that, a constructor with many settings is hard to design. Here is what Go functional options give you.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Readable calls<\/strong>: each option has a name, such as <code>WithPort(443)<\/code>.<\/li>\n\n\n\n<li><strong>Safe defaults<\/strong>: the constructor fills in good values when you pass nothing.<\/li>\n\n\n\n<li><strong>Easy growth<\/strong>: you can add a new option later without breaking old callers.<\/li>\n\n\n\n<li><strong>Clean code<\/strong>: no struct full of zero values that may or may not be set on purpose.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">However, options add a small amount of code. For a type with only two settings, a plain struct is often simpler. So use Go functional options when a type has several optional settings or when you expect it to grow.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How Go Functional Options Work<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The idea has three parts. First, an <code>Option<\/code> is a function type that receives a pointer to the object. Second, each <code>WithSomething<\/code> helper returns an option that changes one field. Third, the constructor builds the object with defaults and then runs every option on it.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-functional-options-pattern-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-functional-options-pattern-diagram-1-1024x640.png\" alt=\"Go Functional Options diagram showing NewServer applying defaults and then the WithPort and WithTLS options\" class=\"wp-image-442\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-functional-options-pattern-diagram-1-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-functional-options-pattern-diagram-1-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-functional-options-pattern-diagram-1-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-functional-options-pattern-diagram-1-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-functional-options-pattern-diagram-1-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">NewServer creates a server with defaults, then runs each option in order. WithPort, WithTLS and WithTimeout each change one field and return control to the constructor.<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Why a Function Type Works So Well<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In Go, functions are values. A closure can remember a variable from the place where it was created. When you call <code>WithPort(443)<\/code>, the returned function remembers the number 443. Later, the constructor runs that function. As a result, the port is set. If you want a refresher, our Go closures post explains this idea in detail.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why the Order of Options Matters<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Options run in the order you pass them, and this order is easy to see. So when two options change the same field, the last one wins. This is usually what people expect. Still, you should document it. This matters most when options depend on each other.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Go Functional Options vs Other Approaches<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">There are a few ways to configure an object in Go. The table below compares them.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Approach<\/th><th>Example<\/th><th>Strength<\/th><th>Weakness<\/th><\/tr><\/thead><tbody><tr><td>Long argument list<\/td><td>NewServer(addr, 8080, 30, true)<\/td><td>Simple for two values<\/td><td>Hard to read, hard to extend<\/td><\/tr><tr><td>Config struct<\/td><td>NewServer(Config{Port: 8080})<\/td><td>Easy to read<\/td><td>Zero values hide intent<\/td><\/tr><tr><td>Builder methods<\/td><td>NewServer().Port(8080).TLS()<\/td><td>Fluent style<\/td><td>More code and mutable state<\/td><\/tr><tr><td>Functional options<\/td><td>NewServer(addr, WithPort(8080))<\/td><td>Clear, safe defaults<\/td><td>Slightly more code<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-functional-options-pattern-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-functional-options-pattern-diagram-2-1024x640.png\" alt=\"Go Functional Options diagram comparing a config struct with functional options\" class=\"wp-image-443\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-functional-options-pattern-diagram-2-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-functional-options-pattern-diagram-2-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-functional-options-pattern-diagram-2-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-functional-options-pattern-diagram-2-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-functional-options-pattern-diagram-2-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">A config struct needs every field to be filled or left as zero. Functional options start from defaults and apply only the changes the caller names.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So a config struct is a fine choice for small types. Functional options shine when defaults matter and the API must stay stable over years. Many well known Go libraries use Go functional options for this reason.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Go Functional Options Hands-On: A Server Type<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Now let&#8217;s write the code. We keep the server tiny so the pattern stays in focus.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: The Type and the Options<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">First, the <code>Server<\/code> struct has four fields. Next, <code>Option<\/code> is a function that takes <code>*Server<\/code>. Then each helper returns a closure that sets one field.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>type Server struct {\n\taddr    string\n\tport    int\n\ttimeout time.Duration\n\ttls     bool\n}\n\ntype Option func(*Server)\n\nfunc WithPort(p int) Option               { return func(s *Server) { s.port = p } }\nfunc WithTimeout(d time.Duration) Option { return func(s *Server) { s.timeout = d } }\nfunc WithTLS() Option                     { return func(s *Server) { s.tls = true } }<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: The Constructor<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Then the constructor takes the address and a variadic list of options. The three dots mean that the caller may pass zero or more of them. It sets safe defaults first and runs each option after that.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func NewServer(addr string, opts ...Option) *Server {\n\ts := &amp;Server{addr: addr, port: 8080, timeout: 30 * time.Second}\n\tfor _, opt := range opts {\n\t\topt(s)\n\t}\n\treturn s\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s look at the key lines. The defaults live in one place, so every caller gets the same safe start. Also, a later change to a default happens in a single line. Then the loop runs each option in the given order. Finally, the return type is a pointer, so the caller shares the same object that the options changed.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Use It<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Finally, we build two servers. The first uses only defaults. The second changes the port, turns on TLS and sets a short timeout.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func main() {\n\ta := NewServer(\"localhost\")\n\tb := NewServer(\"api.example.com\", WithPort(443), WithTLS(), WithTimeout(5*time.Second))\n\tfor _, s := range []*Server{a, b} {\n\t\tfmt.Printf(\"%s:%d timeout=%v tls=%v\\n\", s.addr, s.port, s.timeout, s.tls)\n\t}\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here is the real output from our run.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>localhost:8080 timeout=30s tls=false\napi.example.com:443 timeout=5s tls=true<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">As you can see, the first server keeps every default, because we passed no options. The second server changes exactly the three settings we named. The call reads almost like a sentence, and that is the main gain of Go functional options. In addition, new options never break old calls.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Where You Will See Go Functional Options<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You will meet this pattern in many real projects. Popular libraries use it for clients, servers and loggers. The table below lists a few typical settings and the matching option names.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Setting<\/th><th>Default<\/th><th>Option name<\/th><\/tr><\/thead><tbody><tr><td>Port<\/td><td>8080<\/td><td>WithPort(443)<\/td><\/tr><tr><td>Timeout<\/td><td>30 seconds<\/td><td>WithTimeout(5 * time.Second)<\/td><\/tr><tr><td>Secure mode<\/td><td>Off<\/td><td>WithTLS()<\/td><\/tr><tr><td>Retry count<\/td><td>3<\/td><td>WithRetries(5)<\/td><\/tr><tr><td>Logger<\/td><td>Standard logger<\/td><td>WithLogger(l)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">When you read a library that follows this style, look for the <code>With<\/code> helpers first. They show every setting at a glance. Also, check the constructor for the default values, because they tell you what happens when you pass nothing.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How to Test Options<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Options are easy to test. Build an object with one option, then check the field. For instance, create a server with <code>WithPort(443)<\/code> and confirm that the port is 443. Likewise, create one with no options and check the defaults. Because each option does one thing, each test stays short.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Options That Can Fail<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Sometimes an option gets a bad value, such as port 70000. In that case, let the option return an error. Then the constructor stops at the first error, because a half-built object is not useful. It also wraps the error. The result of a second small program looks like this.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>type Option func(*Server) error\n\nfunc WithPort(p int) Option {\n\treturn func(s *Server) error {\n\t\tif p &lt; 1 || p &gt; 65535 {\n\t\t\treturn errors.New(\"port must be between 1 and 65535\")\n\t\t}\n\t\ts.port = p\n\t\treturn nil\n\t}\n}\n\nfunc NewServer(addr string, opts ...Option) (*Server, error) {\n\ts := &amp;Server{addr: addr, port: 8080}\n\tfor _, opt := range opts {\n\t\tif err := opt(s); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"new server: %w\", err)\n\t\t}\n\t}\n\treturn s, nil\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We call it with a good port and then with a bad one. Here is the real output.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>localhost 9090 &lt;nil&gt;\ntrue new server: port must be between 1 and 65535<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In the first case, the call returns a server and no error. In the second case, it returns a nil server and a clear message. Because of <code>%w<\/code>, the caller can still check the cause with <code>errors.Is<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with Go Functional Options<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Using options for one required value<\/strong>: the address is required, so it stays a normal argument. Options are only for optional settings.<\/li>\n\n\n\n<li><strong>Hidden side effects<\/strong>: an option should only change the object. So avoid network calls or file reads inside it, because they make tests slow.<\/li>\n\n\n\n<li><strong>Missing defaults<\/strong>: without defaults, a caller who passes nothing gets a broken object. Therefore, set safe values first, before any option runs.<\/li>\n\n\n\n<li><strong>Exporting the fields<\/strong>: if fields are public, callers can skip the options. Instead, keep fields private.<\/li>\n\n\n\n<li><strong>Forgetting the order rule<\/strong>: the last option wins. So document any pair of options that conflict.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Go Functional Options<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Name helpers with a With prefix<\/strong>, because the call then reads like English.<\/li>\n\n\n\n<li><strong>Keep one option for one setting<\/strong>, since small pieces are easy to test.<\/li>\n\n\n\n<li><strong>Set defaults in the constructor<\/strong>, which gives every caller the same safe start.<\/li>\n\n\n\n<li><strong>Return an error from options that can fail<\/strong>, so bad input never creates a half-built object.<\/li>\n\n\n\n<li><strong>Use a variadic parameter<\/strong>, because callers can pass zero options and still compile.<\/li>\n\n\n\n<li><strong>Keep the option type exported<\/strong>, so users can build their own lists and reuse them.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To practise Go functional options, add <code>WithLogger(l *log.Logger)<\/code> and <code>WithMaxConns(n int)<\/code> to the server. Then print both values from <code>main<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Hint: add two fields to the struct and set a default for each. After that, make <code>WithMaxConns<\/code> reject numbers below one, as the error version did for ports.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These pages describe the language features and ideas used in this lesson.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/go.dev\/tour\/moretypes\/24\">Tour of Go: Function values<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/go.dev\/ref\/spec#Function_types\">The Go specification: Function types<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/go.dev\/doc\/effective_go#functions\">Effective Go: Functions<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Go functional options configure an object with named, optional settings.<\/li>\n\n\n\n<li>An option is a function type that changes one field through a pointer.<\/li>\n\n\n\n<li>The constructor sets safe defaults and then runs each option in order.<\/li>\n\n\n\n<li>Options can return errors, so bad values stop construction.<\/li>\n\n\n\n<li>Use a config struct for small types and options for growing APIs.<\/li>\n\n\n\n<li>Keep fields private so callers must use the options.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">By now, you can design a constructor that stays clean as it grows. However, we have used methods and receivers in many examples without a full look. So next, we will compare value and pointer receivers in detail.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Next up: <a href=\"https:\/\/smitabharat.com\/blog\/go-methods-receivers\/\">Go methods with value and pointer receivers<\/a><\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>Go functional options are a clean way to build objects that have many settings. In this post, you will learn why long constructors become&hellip;<\/p>\n","protected":false},"author":1,"featured_media":444,"comment_status":"","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[15],"tags":[92,11,77],"swapz_series":[],"class_list":["post-473","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go-lang","tag-go-functional-options","tag-go-lang","tag-intermediate"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Go Functional Options Pattern Explained Simply<\/title>\n<meta name=\"description\" content=\"Learn Go functional options with a simple server example. Set safe defaults, add optional settings and keep your constructors clean.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/smitabharat.com\/blog\/go-functional-options-pattern\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Go Functional Options Pattern Explained Simply\" \/>\n<meta property=\"og:description\" content=\"Learn Go functional options with a simple server example. Set safe defaults, add optional settings and keep your constructors clean.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/smitabharat.com\/blog\/go-functional-options-pattern\/\" \/>\n<meta property=\"og:site_name\" content=\"Smita Bharat - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-06-05T03:30:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-functional-options-pattern-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Smita\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Smita\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-functional-options-pattern\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-functional-options-pattern\\\/\"},\"author\":{\"name\":\"Smita\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"headline\":\"Go Functional Options Pattern Explained Simply\",\"datePublished\":\"2026-06-05T03:30:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-functional-options-pattern\\\/\"},\"wordCount\":1547,\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-functional-options-pattern\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-functional-options-pattern-featured.png\",\"keywords\":[\"Go Functional Options\",\"Go Lang\",\"Intermediate\"],\"articleSection\":[\"Go Lang\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-functional-options-pattern\\\/\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-functional-options-pattern\\\/\",\"name\":\"Go Functional Options Pattern Explained Simply\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-functional-options-pattern\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-functional-options-pattern\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-functional-options-pattern-featured.png\",\"datePublished\":\"2026-06-05T03:30:00+00:00\",\"description\":\"Learn Go functional options with a simple server example. Set safe defaults, add optional settings and keep your constructors clean.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-functional-options-pattern\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-functional-options-pattern\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-functional-options-pattern\\\/#primaryimage\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-functional-options-pattern-featured.png\",\"contentUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-functional-options-pattern-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Go Functional Options featured image: WithPort, WithTLS and default timeout cards\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-functional-options-pattern\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go Functional Options Pattern Explained Simply\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\",\"name\":\"Smita Bharat Blog\",\"description\":\"Golang &amp; Backend Development Tutorials and Interview Questions\",\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"alternateName\":\"Smita Bharat\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\",\"name\":\"Smita\",\"logo\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/smitabharat.com\\\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Go Functional Options Pattern Explained Simply","description":"Learn Go functional options with a simple server example. Set safe defaults, add optional settings and keep your constructors clean.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/smitabharat.com\/blog\/go-functional-options-pattern\/","og_locale":"en_US","og_type":"article","og_title":"Go Functional Options Pattern Explained Simply","og_description":"Learn Go functional options with a simple server example. Set safe defaults, add optional settings and keep your constructors clean.","og_url":"https:\/\/smitabharat.com\/blog\/go-functional-options-pattern\/","og_site_name":"Smita Bharat - Blog","article_published_time":"2026-06-05T03:30:00+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-functional-options-pattern-featured.png","type":"image\/png"}],"author":"Smita","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Smita","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/smitabharat.com\/blog\/go-functional-options-pattern\/#article","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/go-functional-options-pattern\/"},"author":{"name":"Smita","@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"headline":"Go Functional Options Pattern Explained Simply","datePublished":"2026-06-05T03:30:00+00:00","mainEntityOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-functional-options-pattern\/"},"wordCount":1547,"publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-functional-options-pattern\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-functional-options-pattern-featured.png","keywords":["Go Functional Options","Go Lang","Intermediate"],"articleSection":["Go Lang"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/smitabharat.com\/blog\/go-functional-options-pattern\/","url":"https:\/\/smitabharat.com\/blog\/go-functional-options-pattern\/","name":"Go Functional Options Pattern Explained Simply","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-functional-options-pattern\/#primaryimage"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-functional-options-pattern\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-functional-options-pattern-featured.png","datePublished":"2026-06-05T03:30:00+00:00","description":"Learn Go functional options with a simple server example. Set safe defaults, add optional settings and keep your constructors clean.","breadcrumb":{"@id":"https:\/\/smitabharat.com\/blog\/go-functional-options-pattern\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/smitabharat.com\/blog\/go-functional-options-pattern\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/smitabharat.com\/blog\/go-functional-options-pattern\/#primaryimage","url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-functional-options-pattern-featured.png","contentUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-functional-options-pattern-featured.png","width":2400,"height":1260,"caption":"Go Functional Options featured image: WithPort, WithTLS and default timeout cards"},{"@type":"BreadcrumbList","@id":"https:\/\/smitabharat.com\/blog\/go-functional-options-pattern\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/smitabharat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Go Functional Options Pattern Explained Simply"}]},{"@type":"WebSite","@id":"https:\/\/smitabharat.com\/blog\/#website","url":"https:\/\/smitabharat.com\/blog\/","name":"Smita Bharat Blog","description":"Golang &amp; Backend Development Tutorials and Interview Questions","publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"alternateName":"Smita Bharat","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/smitabharat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339","name":"Smita","logo":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/smitabharat.com\/blog"]}]}},"_links":{"self":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/473","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/comments?post=473"}],"version-history":[{"count":0,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/473\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media\/444"}],"wp:attachment":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media?parent=473"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/categories?post=473"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/tags?post=473"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=473"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}