github.com/klaytn/klaytn@v1.12.1/cmd/homi/docker/service/eth_stats.go (about)

     1  // Copyright 2017 AMIS Technologies
     2  // This file is part of the go-ethereum library.
     3  //
     4  // The go-ethereum library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The go-ethereum library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package service
    18  
    19  import (
    20  	"bytes"
    21  	"fmt"
    22  	"text/template"
    23  )
    24  
    25  type KlayStats struct {
    26  	Secret string
    27  	IP     string
    28  }
    29  
    30  func NewEthStats(ip string, secret string) *KlayStats {
    31  	return &KlayStats{
    32  		IP:     ip,
    33  		Secret: secret,
    34  	}
    35  }
    36  
    37  func (c KlayStats) Host() string {
    38  	return fmt.Sprintf("%v@%v:3000", c.Secret, c.IP)
    39  }
    40  
    41  func (c KlayStats) String() string {
    42  	tmpl, err := template.New("klay_stats").Parse(klayStatsTemplate)
    43  	if err != nil {
    44  		fmt.Printf("Failed to parse template, %v", err)
    45  		return ""
    46  	}
    47  
    48  	result := new(bytes.Buffer)
    49  	err = tmpl.Execute(result, c)
    50  	if err != nil {
    51  		fmt.Printf("Failed to render template, %v", err)
    52  		return ""
    53  	}
    54  
    55  	return result.String()
    56  }
    57  
    58  var klayStatsTemplate = `klay-stats:
    59      image: quay.io/amis/klaystats:latest
    60      ports:
    61        - '3000:3000'
    62      environment:
    63        - WS_SECRET={{ .Secret }}
    64      restart: always
    65      networks:
    66        app_net:
    67          ipv4_address: {{ .IP }}`