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 7542509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:11:08+00:00 2026-05-30T08:11:08+00:00

In trying to understand Go, I ran into this piece of code in websocket.go

  • 0

In trying to understand Go, I ran into this piece of code in websocket.go (snipped):

type frameHandler interface {
    HandleFrame(frame frameReader) (r frameReader, err error)
    WriteClose(status int) (err error)
}

// Conn represents a WebSocket connection.
type Conn struct {
    config  *Config
    request *http.Request
    .
    .
    frameHandler
    PayloadType        byte
    defaultCloseStatus int
}

In the Conn type the frameHandler stands there all alone? An interface without a name?
Later on in the code they even try check if the poor interface is nil:

Conn(a).frameHandler == nil

My own guess is that the frameHandler within the struct is a type which matches the frameHandler interface, and on top of that will have the name frameHandler. Is this correct? Hehe, fun language anyhow.

  • 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-30T08:11:09+00:00Added an answer on May 30, 2026 at 8:11 am

    This line:

        frameHandler
    

    is roughly equivalent to this:

        frameHandler frameHandler
    

    in that frameHandler is both the name of the field and its type. In addition, it adds all the fields and methods of the frameHandler to the Conn, so if conn is a Conn, then conn.WriteClose(0) means conn.frameHandler.WriteClose(0).

    As the Go Programming Language Specification puts it:

    A field declared with a type but no explicit field name is an anonymous field (colloquially called an embedded field). Such a field type must be specified as a type name T or as a pointer to a non-interface type name *T, and T itself may not be a pointer type. The unqualified type name acts as the field name.

    // A struct with four anonymous fields of type T1, *T2, P.T3 and *P.T4
    struct {
        T1        // field name is T1
        *T2       // field name is T2
        P.T3      // field name is T3
        *P.T4     // field name is T4
        x, y int  // field names are x and y
    }

    The following declaration is illegal because field names must be unique in a struct type:

    struct {
        T         // conflicts with anonymous field *T and *P.T
        *T        // conflicts with anonymous field T and *P.T
        *P.T      // conflicts with anonymous field T and *T
    }

    Fields and methods (§Method declarations) of an anonymous field are promoted to be ordinary fields and methods of the struct (§Selectors). The following rules apply for a struct type named S and a type named T:

    • If S contains an anonymous field T, the
      method set of S includes the
      method set of T.
    • If S contains an anonymous field *T, the
      method set of S includes the method set of *T
      (which itself includes the method set of T).
    • If S contains an anonymous field T or
      *T, the method set of *S includes the
      method set of *T (which itself includes the method
      set of T).

    A field declaration may be followed by an optional string literal tag, which becomes an attribute for all the fields in the corresponding field declaration. The tags are made visible through a reflection interface but are otherwise ignored.

    // A struct corresponding to the TimeStamp protocol buffer.
    // The tag strings define the protocol buffer field numbers.
    struct {
        microsec  uint64 "field 1"
        serverIP6 uint64 "field 2"
        process   string "field 3"
    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to understand Ruby a bit better, I ran into this code surfing the
I'm learning jQuery by trying to understand other people's code. I ran into this:
I am trying to understand someone's code and ran into this. There is a
Trying to understand the math of this code snippet. A token is provided which
I was looking over some C++ code and I ran into this memcpy function.
Previously, I ran into a problem trying to share a type definition between my
I ran into some trouble trying to implement a smart equality test macro-type template
I've been trying to understand Oracle database's use of data type = number. I
I am using Code::Blocks 10.05, and the GNU GCC Compiler. Basically, I ran into
I am currently busy with assembly and ran into the following problem: I'm trying

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.