599 Internal Exception, https://fastapi.metacpan.org/v1/release/_search, Can't verify SSL peers without knowing which Certificate Authorities to trust This problem can be fixed by either setting the PERL_LWP_SSL_CA_FILE envirionment variable or by installing the Mozilla::CA module. To disable verification of SSL peers set the PERL_LWP_SSL_VERIFY_HOSTNAME envirionment variable to 0. If you do this you can't be sure that you communicate with the expected peer.
type IntPtr struct {
v *int
}
func (p IntPtr) Format(f fmt.State, c rune) {
if p.v == nil {
fmt.Fprintf(f, "<nil>")
return
}
format := "%"if f.Flag('0') {
format += "0"
}
if wid, ok := f.Width(); ok {
format += fmt.Sprintf("%d", wid)
}
if prec, ok := f.Precision(); ok {
format += fmt.Sprintf(".%d", prec)
}
format += string(c)
fmt.Fprintf(f, format, *p.v)
}
func main() {
i := 10
p := IntPtr{&i}
fmt.Printf("%[1]d %04[1]x\n", p)
// Output: 10 000a
}
なぜIntPtrを構造体にしているか
Go言語仕様で、メソッドレシーバの基本型(base type)にポインタやインターフェイスを使えません。基本型というのは、メソッドのレシーバ型は T または *T が使えるけれども、両方における T のことです。これはMethod declarationsに書かれています。
Its type must be of the form T or *T (possibly using parentheses) where T is a type name. The type denoted by T is called the receiver base type; it must not be a pointer or interface type and it must be defined in the same package as the method.
なので、
type IntPtr *intfunc (p IntPtr) String(f fmt.State, c rune) {
}
上のコードは、
invalid receiver type IntPtr (IntPtr is a pointer type)
// 定義package list
type Element struct {
Value interface{}
}
func (e *Element) Next() *Element
func (e *Element) Prev() *Element
// 使い方package main
l := list.New()
l.PushFront("test")
for e := l.Front(); e != nil; e = e.Next() {
s := e.Value.(string)
if s == "test" {
...
}
}
// これはできない
a := []int32{0, 1, 2}
sort.Ints(a) // cannot use s (type []int32) as type []int in argument to sort.Ints// 詰め替えてあげる必要がある
a1 := make([]int, len(a))
for i := range a {
a1[i] = int(a[i])
}
sort.Ints(a1)
// Copyright xxx// +build darwin/*Godoc はGoのパッケージドキュメント情報をQiitaで紹介するためのパッケージです。そのままサンプルとして使えます。リポジトリは https://github.com/lufia/godoc-sample です。How to read a documentドキュメントを読むためにはgo docコマンドまたはgodocコマンドが使えます。How to write a documentパッケージドキュメントはpackage句の直前に書く必要がありますが、Build constraintsはpackageよりも前に書かなければなりません。そのため、記述する順番としては、Build constraintsが先になります。空行を入れると、別の段落として区切ることができます。 インデントすると、ソースコードのような 整形されたテキストも書けますHeadingアルファベットの大文字で始まり、句読点を含まない1行だけの段落があれば、それはヘッダとして装飾されます。ただし、ヘッダを2つ以上続けることはできません。次の行はヘッダになりますが、その次は同じルールにも関わらず普通の段落です。This is a headerThis is not a header*/package qiita
上記のコードで、パッケージ名をqiita_testとしてパッケージ本体と分けているのは、そうした方が、コード例にパッケージ名を記述することができて親切だからです。Goのパッケージは通常、異なるパッケージを同じディレクトリに入れることはできませんが、_testの場合は外部テストパッケージ(external test といって特別らしいです。