Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6038393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:12:47+00:00 2026-05-23T06:12:47+00:00

How is the following function implemented? func handle(pattern string, handler interface{}) { // …

  • 0

How is the following function implemented?

func handle(pattern string, handler interface{}) {
    // ... what goes here? ...
    http.Handle(pattern, ?)
}

handle("/foo", func(w http.ResponseWriter, r http.Request) { io.WriteString(w, "foo") }
handle("/bar", BarHandler{})

handle() is passed either a function which matches the type of http.HandlerFunc or a type which implements the http.Handler interface.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:12:49+00:00Added an answer on May 23, 2026 at 6:12 am

    Instead of resorting to reflection, I would do it this way:

    func handle(pattern string, handler interface{}) {
        var h http.Handler
        switch handler := handler.(type) {
        case http.Handler:
            h = handler
        case func(http.ResponseWriter, *http.Request):
            h = http.HandlerFunc(handler)
        default:
            // error
        }
        http.Handle(pattern, h)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to implement the following pattern function: MethodInfo GetMethod( Expression<Func<TTarget, EventHandler<TEventArgs>>> method)
I have the following factorial function implemented in XSLT: <?xml version=1.0?> <xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform>
I have implemented the repository pattern using the following generic interface. public interface IRepository<T>
How can the following function be implemented in various languages? Calculate the (x,y) point
I am working with a COM plugin interface that has the following function definition:
Why does this: Private [Function] As Func(Of Double, String) = Function(ByRef z As Double)
I have a WPF application. I have implemented the following function, but no one
I have implemented Ruby C extension(i.e. Invoking C function from ruby script) Following is
Given the following interface: interface ISoapInterface { public static function registerSoapTypes( &$wsdl ); public
[question update according to updated requirements] I've implemented following function which should return either

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.