Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
Improve the quality of comments in the documents
Browse files Browse the repository at this point in the history
Signed-off-by: yuxiaobo <yuxiaobogo@163.com>
  • Loading branch information
yuxiaobo96 committed Sep 25, 2019
1 parent a37632b commit f43961e
Show file tree
Hide file tree
Showing 52 changed files with 132 additions and 132 deletions.
4 changes: 2 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var (
defaultVersion = "v1.24"
)

// APIClient is an API client that performs all operations
// APIClient is an API client that performs all operations.
// against a server
type APIClient struct {
proto string // socket type
Expand All @@ -44,7 +44,7 @@ type APIClient struct {
version string
}

// TLSConfig contains information of TLS which users can specify
// TLSConfig contains information of TLS which users can specify.
type TLSConfig struct {
CA string `json:"tlscacert,omitempty"`
Cert string `json:"tlscert,omitempty"`
Expand Down
4 changes: 2 additions & 2 deletions client/httputils.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func ParseHost(host string) (*url.URL, string, string, error) {
return u, basePath, strings.TrimPrefix(host, u.Scheme+"://"), nil
}

// GenTLSConfig returns a tls config object according to inputting parameters.
// GenTLSConfig returns a TLS config object according to inputting parameters.
func GenTLSConfig(key, cert, ca string) (*tls.Config, error) {
tlsConfig := &tls.Config{}
tlsCert, err := tls.LoadX509KeyPair(cert, key)
Expand All @@ -93,7 +93,7 @@ func GenTLSConfig(key, cert, ca string) (*tls.Config, error) {
return tlsConfig, nil
}

// NewHTTPClient creates a http client using url and tlsconfig
// NewHTTPClient creates a http client using url and tlsconfig.
func NewHTTPClient(u *url.URL, tlsConfig *tls.Config, dialTimeout time.Duration) *http.Client {
tr := &http.Transport{
TLSClientConfig: tlsConfig,
Expand Down
2 changes: 1 addition & 1 deletion client/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/dragonflyoss/Dragonfly/apis/types"
)

// CommonAPIClient defines common methods of api client
// CommonAPIClient defines common methods of api client.
type CommonAPIClient interface {
PreheatAPIClient
}
Expand Down
2 changes: 1 addition & 1 deletion client/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (e RespError) Error() string {
return e.msg
}

// Code returns the response code
// Code returns the response code.
func (e RespError) Code() int {
return e.code
}
Expand Down
2 changes: 1 addition & 1 deletion client/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func ensureCloseReader(resp *Response) error {
if resp != nil && resp.Body != nil {
defer resp.Body.Close()

// close body ReadCloser to make Transport reuse the connection
// Close body ReadCloser to make Transport reuse the connection.
_, err := io.CopyN(ioutil.Discard, resp.Body, 512)
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/dfdaemon/app/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ J88xU3xXABE5QsNNbqLcMgQoXeMmqk1WuUhxXzTXT5h5gdW53faxV5M5Cb3zI8My
PPpBF5Cw+khgkJcY/ezKjHIvyABJwdzW8aAqwDBFAQ==
-----END CERTIFICATE-----`

// TestDecodeWithYAML tests if config.URL and config.Regexp are decoded correctly
// TestDecodeWithYAML tests if config.URL and config.Regexp are decoded correctly.
func (ts *rootTestSuite) TestDecodeWithYAML() {
r := ts.Require()
v := viper.New()
Expand Down
2 changes: 1 addition & 1 deletion cmd/supernode/app/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func runSuperNode() error {
return d.Run()
}

// initLog initializes log Level and log format
// initLog initializes log Level and log format.
func initLog(logger *logrus.Logger, logPath string) error {
logFilePath := path.Join(options.HomeDir, "logs", logPath)

Expand Down
48 changes: 24 additions & 24 deletions dfdaemon/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (p *Properties) Validate() error {
return nil
}

// DFGetConfig returns config for dfget downloader
// DFGetConfig returns config for dfget downloader.
func (p *Properties) DFGetConfig() DFGetConfig {
// init DfgetFlags
var dfgetFlags []string
Expand All @@ -154,7 +154,7 @@ func (p *Properties) DFGetConfig() DFGetConfig {
return dfgetConfig
}

// DFGetConfig configures how dfdaemon calls dfget
// DFGetConfig configures how dfdaemon calls dfget.
type DFGetConfig struct {
DfgetFlags []string `yaml:"dfget_flags"`
SuperNodes []string `yaml:"supernodes"`
Expand All @@ -176,7 +176,7 @@ type RegistryMirror struct {
Insecure bool `yaml:"insecure" json:"insecure"`
}

// TLSConfig returns the tls.Config used to communicate with the mirror
// TLSConfig returns the tls.Config used to communicate with the mirror.
func (r *RegistryMirror) TLSConfig() *tls.Config {
if r == nil {
return nil
Expand All @@ -193,26 +193,26 @@ func (r *RegistryMirror) TLSConfig() *tls.Config {
return cfg
}

// HijackConfig represents how dfdaemon hijacks http requests
// HijackConfig represents how dfdaemon hijacks http requests.
type HijackConfig struct {
Cert string `yaml:"cert" json:"cert"`
Key string `yaml:"key" json:"key"`
Hosts []*HijackHost `yaml:"hosts" json:"hosts"`
}

// HijackHost is a hijack rule for the hosts that matches Regx
// HijackHost is a hijack rule for the hosts that matches Regx.
type HijackHost struct {
Regx *Regexp `yaml:"regx" json:"regx"`
Insecure bool `yaml:"insecure" json:"insecure"`
Certs *CertPool `yaml:"certs" json:"certs"`
}

// URL is simple wrapper around url.URL to make it unmarshallable from a string
// URL is simple wrapper around url.URL to make it unmarshallable from a string.
type URL struct {
*url.URL
}

// NewURL parses url from the given string
// NewURL parses url from the given string.
func NewURL(s string) (*URL, error) {
u, err := url.Parse(s)
if err != nil {
Expand All @@ -222,12 +222,12 @@ func NewURL(s string) (*URL, error) {
return &URL{u}, nil
}

// UnmarshalYAML implements yaml.Unmarshaller
// UnmarshalYAML implements yaml.Unmarshaller.
func (u *URL) UnmarshalYAML(unmarshal func(interface{}) error) error {
return u.unmarshal(unmarshal)
}

// UnmarshalJSON implements json.Unmarshaller
// UnmarshalJSON implements json.Unmarshaller.
func (u *URL) UnmarshalJSON(b []byte) error {
return u.unmarshal(func(v interface{}) error { return json.Unmarshal(b, v) })
}
Expand All @@ -247,29 +247,29 @@ func (u *URL) unmarshal(unmarshal func(interface{}) error) error {
return nil
}

// MarshalJSON implements json.Marshaller to print the url
// MarshalJSON implements json.Marshaller to print the url.
func (u *URL) MarshalJSON() ([]byte, error) {
return json.Marshal(u.String())
}

// MarshalYAML implements yaml.Marshaller to print the url
// MarshalYAML implements yaml.Marshaller to print the url.
func (u *URL) MarshalYAML() (interface{}, error) {
return u.String(), nil
}

// CertPool is a wrapper around x509.CertPool, which can be unmarshalled and
// constructed from a list of filenames
// constructed from a list of filenames.
type CertPool struct {
Files []string
*x509.CertPool
}

// UnmarshalYAML implements yaml.Unmarshaller
// UnmarshalYAML implements yaml.Unmarshaller.
func (cp *CertPool) UnmarshalYAML(unmarshal func(interface{}) error) error {
return cp.unmarshal(unmarshal)
}

// UnmarshalJSON implements json.Unmarshaller
// UnmarshalJSON implements json.Unmarshaller.
func (cp *CertPool) UnmarshalJSON(b []byte) error {
return cp.unmarshal(func(v interface{}) error { return json.Unmarshal(b, v) })
}
Expand All @@ -288,22 +288,22 @@ func (cp *CertPool) unmarshal(unmarshal func(interface{}) error) error {
return nil
}

// MarshalJSON implements json.Marshaller to print the cert pool
// MarshalJSON implements json.Marshaller to print the cert pool.
func (cp *CertPool) MarshalJSON() ([]byte, error) {
return json.Marshal(cp.Files)
}

// MarshalYAML implements yaml.Marshaller to print the cert pool
// MarshalYAML implements yaml.Marshaller to print the cert pool.
func (cp *CertPool) MarshalYAML() (interface{}, error) {
return cp.Files, nil
}

// Regexp is simple wrapper around regexp.Regexp to make it unmarshallable from a string
// Regexp is a simple wrapper around regexp. Regexp to make it unmarshallable from a string.
type Regexp struct {
*regexp.Regexp
}

// NewRegexp returns new Regexp instance compiled from the given string
// NewRegexp returns a new Regexp instance compiled from the given string.
func NewRegexp(exp string) (*Regexp, error) {
r, err := regexp.Compile(exp)
if err != nil {
Expand All @@ -312,12 +312,12 @@ func NewRegexp(exp string) (*Regexp, error) {
return &Regexp{r}, nil
}

// UnmarshalYAML implements yaml.Unmarshaller
// UnmarshalYAML implements yaml.Unmarshaller.
func (r *Regexp) UnmarshalYAML(unmarshal func(interface{}) error) error {
return r.unmarshal(unmarshal)
}

// UnmarshalJSON implements json.Unmarshaller
// UnmarshalJSON implements json.Unmarshaller.
func (r *Regexp) UnmarshalJSON(b []byte) error {
return r.unmarshal(func(v interface{}) error { return json.Unmarshal(b, v) })
}
Expand All @@ -334,12 +334,12 @@ func (r *Regexp) unmarshal(unmarshal func(interface{}) error) error {
return err
}

// MarshalJSON implements json.Marshaller to print the regexp
// MarshalJSON implements json.Marshaller to print the regexp.
func (r *Regexp) MarshalJSON() ([]byte, error) {
return json.Marshal(r.String())
}

// MarshalYAML implements yaml.Marshaller to print the regexp
// MarshalYAML implements yaml.Marshaller to print the regexp.
func (r *Regexp) MarshalYAML() (interface{}, error) {
return r.String(), nil
}
Expand Down Expand Up @@ -371,7 +371,7 @@ type Proxy struct {
Direct bool `yaml:"direct" json:"direct"`
}

// NewProxy returns a new proxy rule with given attributes
// NewProxy returns a new proxy rule with given attributes.
func NewProxy(regx string, useHTTPS bool, direct bool) (*Proxy, error) {
exp, err := NewRegexp(regx)
if err != nil {
Expand All @@ -385,7 +385,7 @@ func NewProxy(regx string, useHTTPS bool, direct bool) (*Proxy, error) {
}, nil
}

// Match checks if the given url matches the rule
// Match checks if the given url matches the rule.
func (r *Proxy) Match(url string) bool {
return r.Regx != nil && r.Regx.MatchString(url)
}
6 changes: 3 additions & 3 deletions dfdaemon/downloader/dfget/dfget.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ import (
log "github.com/sirupsen/logrus"
)

// DFGetter implements Downloader to download file by dragonfly
// DFGetter implements Downloader to download file by dragonfly.
type DFGetter struct {
config config.DFGetConfig
}

// NewGetter returns a dfget downloader from the given config
// NewGetter returns a dfget downloader from the given config.
func NewGetter(cfg config.DFGetConfig) *DFGetter {
return &DFGetter{config: cfg}
}
Expand All @@ -60,7 +60,7 @@ func (dfGetter *DFGetter) Download(url string, header map[string][]string, name
return "", fmt.Errorf("dfget fail(%s):%v", cmd.ProcessState.String(), err)
}

// getCommand returns the command to download the given resource
// getCommand returns the command to download the given resource.
func (dfGetter *DFGetter) getCommand(
url string, header map[string][]string, output string,
) (cmd *exec.Cmd) {
Expand Down
2 changes: 1 addition & 1 deletion dfdaemon/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ type Interface interface {
Download(url string, header map[string][]string, name string) (string, error)
}

// Factory is a function that returns a new downloader
// Factory is a function that returns a new downloader.
type Factory func() Interface
2 changes: 1 addition & 1 deletion dfdaemon/exception/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (authError *AuthError) Error() string {
return "NOT AUTH"
}

// IsNotAuth is to judge whether an error is AuthError
// IsNotAuth is to judge whether an error is AuthError.
func IsNotAuth(err error) bool {
if _, ok := err.(*AuthError); ok {
return true
Expand Down
2 changes: 1 addition & 1 deletion dfdaemon/handler/env_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/spf13/viper"
)

// getEnv returns the environments of dfdaemon
// getEnv returns the environments of dfdaemon.
func getEnv(w http.ResponseWriter, r *http.Request) {
logrus.Debugf("access:%s", r.URL.String())
json.NewEncoder(w).Encode(ensureStringKey(viper.AllSettings()))
Expand Down
2 changes: 1 addition & 1 deletion dfdaemon/handler/root_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp"
)

// New returns a new http mux for dfdaemon
// New returns a new http mux for dfdaemon.
func New() *http.ServeMux {
s := http.DefaultServeMux
s.HandleFunc("/args", getArgs)
Expand Down
2 changes: 1 addition & 1 deletion dfdaemon/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ func (l *singleUseListener) Close() error { return nil }

func (l *singleUseListener) Addr() net.Addr { return l.c.LocalAddr() }

// A customCloseConn implements net.Conn and calls f before closing the underlying net.Conn
// A customCloseConn implements net.Conn and calls f before closing the underlying net.Conn.
type customCloseConn struct {
net.Conn
f func()
Expand Down
Loading

0 comments on commit f43961e

Please sign in to comment.