Go (Golang) Functional Options Pattern

Поделиться
HTML-код
  • Опубликовано: 4 ноя 2024
  • Go (Golang) Functional Option Design Pattern
    The Functional Options pattern is pretty useful when building Go packages that need to be configured with different and varying configuration options. One of the ways you could configure that is by using a Config struct or some other pre-defined package level structs. Although that works it's not as elegant and robust as the Functional Option pattern which allows you to build countless extensions to your package functionality without breaking its public APIs (method definition and interfaces)
    Source Code - play.golang.or...
    💼 Golang Cafe - golang.cafe
    📬 Golang Cafe Jobs Newsletter - golang.cafe/ne...
    🐦 Golang Cafe Twitter - / golangcafe
    📣 Telegram Channel - t.me/golangcafe
    🙏 Found this video useful? Help me make more by donating $5.00 - golang.cafe/5USD

Комментарии • 17

  • @akramulfata9815
    @akramulfata9815 2 месяца назад +1

    So cool

  • @tomascoelhopinto
    @tomascoelhopinto 9 месяцев назад +1

    Very clear thanks 👍

  • @GolangDojo
    @GolangDojo 3 года назад +3

    This is beautiful! I should create a design pattern series as well. Love your channel, you always talk about things that I often overlook from my day job :)

  • @nicolasparada
    @nicolasparada 3 года назад +1

    Great pattern.
    I want to emphasize to define the `Option` type. So on godoc, all functional options are grouped under `Option` type.

  • @ChristopherHayles
    @ChristopherHayles 3 года назад

    Nice clear explanation.

  • @opeyemipopoola3475
    @opeyemipopoola3475 3 года назад

    thnaks for this. learning day by day with your videos.

    • @GolangCafe
      @GolangCafe  3 года назад

      I am glad to hear this, thanks for watching!

  • @canopusinthenorth
    @canopusinthenorth 2 года назад

    Came for Go, stayed for VIM.. you must do a video on your vim setup

  • @TheKhanj
    @TheKhanj Год назад

    What are the advantages and disadvantages over builder pattern? 🤔 Cause you know we are using closures in here which are technically objects which have state + a method for closure call, so why not put those states in builder object? Oh I see, this one is more dynamic, we can compose different options array at runtime, it requires another layer or something to do it in builder pattern... It was nice then :)

    • @TimMattison
      @TimMattison Год назад

      I didn’t get it at first. But then I liked and subscribed. Clever, but in a good way.

  • @xxxxxx-wq2rd
    @xxxxxx-wq2rd 2 года назад

    great idea!

  • @panda-jf4ku9et2u
    @panda-jf4ku9et2u 3 года назад

    So cool, man!

    • @GolangCafe
      @GolangCafe  3 года назад

      Thank you! I am glad you liked it

  • @rabingaire
    @rabingaire 3 года назад

    great video