LoginSignup
1
0

More than 3 years have passed since last update.

Goのstruct(構造体)はフィールドなしでも定義できる

Posted at

概要

タイトルのままです。

フィールドなしでメソッドだけ定義したかったのですが、パッと調べてもわからなかったので、実際に試して知りました。

『そんなもん知ってるわ!!』という方はブラウザバックどうぞ

検証結果

main.go
package main

import (
    "log"
)

func main() {
    n := Network{}
    log.Print(n.CreateURL())
}

type Network struct {
}

func (n *Network) CreateURL() string {
    // TODO: 引数を受け取ってURLを返す
    return "https://github.com/"
}
実行結果
# go run main.go
2009/11/10 23:00:00 https://github.com/

実際に動かせる

こちら =>

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0