// Copyright 2009 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.//go:build unix || js || wasip1// Read system port mappings from /etc/servicespackage netimport ()var onceReadServices sync.Oncefunc readServices() { , := open("/etc/services")if != nil {return }defer .close()for , := .readLine(); ; , = .readLine() {// "http 80/tcp www www-http # World Wide Web HTTP"if := bytealg.IndexByteString(, '#'); >= 0 { = [:] } := getFields()iflen() < 2 {continue } := [1] // "80/tcp" , , := dtoi()if ! || <= 0 || >= len() || [] != '/' {continue } := [+1:] // "tcp" , := services[]if ! { = make(map[string]int)services[] = }for := 0; < len(); ++ {if != 1 { // f[1] was port/net [[]] = } } }}// goLookupPort is the native Go implementation of LookupPort.func goLookupPort(, string) ( int, error) {onceReadServices.Do(readServices)returnlookupPortMap(, )}
The pages are generated with Goldsv0.7.0-preview. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.