本文整理汇总了Golang中fmt.Sprintln函数的典型用法代码示例。如果您正苦于以下问题:Golang Sprintln函数的具体用法?Golang Sprintln怎么用?Golang Sprintln使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Sprintln函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Error
func (in *Input) Error(args ...interface{}) {
if panicOnError {
panic(fmt.Errorf("%s:%d: %s", in.File(), in.Line(), fmt.Sprintln(args...)))
}
fmt.Fprintf(os.Stderr, "%s:%d: %s", in.File(), in.Line(), fmt.Sprintln(args...))
os.Exit(1)
}
示例2: Start
func (e *Engine) Start() {
var err error
e.shader.program, err = LoadProgram("shader.v.glsl", "shader.f.glsl")
if err != nil {
panic(fmt.Sprintln("LoadProgram failed:", err))
}
e.shape.buf = gl.CreateBuffer()
gl.BindBuffer(gl.ARRAY_BUFFER, e.shape.buf)
gl.BufferData(gl.ARRAY_BUFFER, EncodeObject(cubeData), gl.STATIC_DRAW)
e.shader.vertCoord = gl.GetAttribLocation(e.shader.program, "vertCoord")
e.shader.vertTexCoord = gl.GetAttribLocation(e.shader.program, "vertTexCoord")
e.shader.projection = gl.GetUniformLocation(e.shader.program, "projection")
e.shader.view = gl.GetUniformLocation(e.shader.program, "view")
e.shader.model = gl.GetUniformLocation(e.shader.program, "model")
e.shape.texture, err = LoadTexture("gopher.png")
if err != nil {
panic(fmt.Sprintln("LoadTexture failed:", err))
}
e.started = time.Now()
}
示例3: String
func (p *PackageDeprecated) String() string {
return fmt.Sprintln(" root:", p.root) +
fmt.Sprintln(" name:", p.name) +
fmt.Sprintln("version:", p.version) +
fmt.Sprintln(" source:", p.Source) +
fmt.Sprintln(" tmpdir:", p.tmpdir)
}
示例4: String
func (this DepthMap) String() string {
s := fmt.Sprintln("Depths", len(this))
for _, dData := range this {
s += fmt.Sprintln("Depth:", dData.depth, "Items:", len(dData.array))
}
return s
}
示例5: runPrune
func runPrune(dockerCli *command.DockerCli, opts pruneOptions) (spaceReclaimed uint64, output string, err error) {
pruneFilters := opts.filter.Value()
pruneFilters.Add("dangling", fmt.Sprintf("%v", !opts.all))
warning := danglingWarning
if opts.all {
warning = allImageWarning
}
if !opts.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) {
return
}
report, err := dockerCli.Client().ImagesPrune(context.Background(), pruneFilters)
if err != nil {
return
}
if len(report.ImagesDeleted) > 0 {
output = "Deleted Images:\n"
for _, st := range report.ImagesDeleted {
if st.Untagged != "" {
output += fmt.Sprintln("untagged:", st.Untagged)
} else {
output += fmt.Sprintln("deleted:", st.Deleted)
}
}
spaceReclaimed = report.SpaceReclaimed
}
return
}
示例6: UpdatePortContext
func UpdatePortContext(ovs *libovsdb.OvsdbClient, portName string, key string, context string) error {
config := make(map[string]string)
config[CONTEXT_KEY] = key
config[CONTEXT_VALUE] = context
other_config, _ := libovsdb.NewOvsMap(config)
mutation := libovsdb.NewMutation("other_config", "insert", other_config)
condition := libovsdb.NewCondition("name", "==", portName)
// simple mutate operation
mutateOp := libovsdb.Operation{
Op: "mutate",
Table: "Interface",
Mutations: []interface{}{mutation},
Where: []interface{}{condition},
}
operations := []libovsdb.Operation{mutateOp}
reply, _ := ovs.Transact("Open_vSwitch", operations...)
if len(reply) < len(operations) {
return errors.New("Number of Replies should be atleast equal to number of Operations")
}
for i, o := range reply {
if o.Error != "" && i < len(operations) {
return errors.New(fmt.Sprintln("Transaction Failed due to an error :", o.Error, " details:", o.Details, " in ", operations[i]))
} else if o.Error != "" {
return errors.New(fmt.Sprintln("Transaction Failed due to an error :", o.Error))
}
}
return nil
}
示例7: LoadRawTx
func LoadRawTx(buf []byte) (s string) {
txd, er := hex.DecodeString(string(buf))
if er != nil {
txd = buf
}
// At this place we should have raw transaction in txd
tx, le := btc.NewTx(txd)
if tx == nil || le != len(txd) {
s += fmt.Sprintln("Could not decode transaction file or it has some extra data")
return
}
tx.Hash = btc.NewSha2Hash(txd)
var missinginp bool
var totinp, totout uint64
s, missinginp, totinp, totout, er = DecodeTx(tx)
if er != nil {
return
}
network.TxMutex.Lock()
if missinginp {
network.TransactionsToSend[tx.Hash.Hash] = &network.OneTxToSend{Tx: tx, Data: txd, Own: 2, Firstseen: time.Now(),
Volume: totout}
} else {
network.TransactionsToSend[tx.Hash.Hash] = &network.OneTxToSend{Tx: tx, Data: txd, Own: 1, Firstseen: time.Now(),
Volume: totinp, Fee: totinp - totout}
}
network.TxMutex.Unlock()
s += fmt.Sprintln("Transaction added to the memory pool. Please double check its details above.")
s += fmt.Sprintln("If it does what you intended, you can send it the network.\nUse TxID:", tx.Hash.String())
return
}
示例8: String
func (p *Pattern) String() string {
if p == nil {
return ""
}
var buffer bytes.Buffer
buffer.WriteString(fmt.Sprintln("Saved with HW Version:", p.version))
buffer.WriteString(fmt.Sprintln("Tempo:", p.tempo))
for _, j := range p.track {
buffer.WriteString(fmt.Sprint("(", strconv.Itoa(int(j.id)), ") ", j.name, "\t"))
step := 0
for i := 0; i < 16; i++ {
if math.Mod(float64(step), 4) == 0 {
//buffer.WriteByte(0x7C)
buffer.WriteString("|")
}
if bytes.Compare(j.step[i:i+1], []byte{0x00}) == 0 {
buffer.WriteString("-")
} else if bytes.Compare(j.step[i:i+1], []byte{0x01}) == 0 {
buffer.WriteString("x")
} else {
// incase if the byte is not 0x00 0x01
buffer.WriteString(" ")
}
step = step + 1
if i == 15 {
buffer.WriteString("|")
//buffer.WriteByte(0x7C)
}
}
buffer.WriteString("\n")
}
return buffer.String()
}
示例9: MakeTaitBryan
func MakeTaitBryan(h, p, r int) TaitBryan {
if h < 0 || h > 3 {
panic(fmt.Sprintln("Heading out of bound: %i not in [0, 1, 2].", h))
}
if p < 0 || p > 3 {
panic(fmt.Sprintln("Pitch out of bound: %i not in [0, 1, 2].", p))
}
if r < 0 || r > 3 {
panic(fmt.Sprintln("Roll out of bound: %i not in [0, 1, 2].", r))
}
if h == p {
panic("Header and pitch must be different.")
}
if h == r {
panic("Header and roll must be different.")
}
if p == r {
panic("Pitch and roll must be different.")
}
var tb TaitBryan
tb.h = h
tb.p = p
tb.r = r
return tb
}
示例10: queryShowVariables
// Query the SHOW variables from the query map
// TODO: make this more functional
func queryShowVariables(ch chan<- prometheus.Metric, db *sql.DB, variableMap map[string]MetricMapNamespace) []error {
log.Debugln("Querying SHOW variables")
nonFatalErrors := []error{}
for _, mapping := range variableMap {
for columnName, columnMapping := range mapping.columnMappings {
// Check for a discard request on this value
if columnMapping.discard {
continue
}
// Use SHOW to get the value
row := db.QueryRow(fmt.Sprintf("SHOW %s;", columnName))
var val interface{}
err := row.Scan(&val)
if err != nil {
nonFatalErrors = append(nonFatalErrors, errors.New(fmt.Sprintln("Error scanning runtime variable:", columnName, err)))
continue
}
fval, ok := columnMapping.conversion(val)
if !ok {
nonFatalErrors = append(nonFatalErrors, errors.New(fmt.Sprintln("Unexpected error parsing column: ", namespace, columnName, val)))
continue
}
ch <- prometheus.MustNewConstMetric(columnMapping.desc, columnMapping.vtype, fval)
}
}
return nonFatalErrors
}
示例11: Save
//compresses ram banks and stores as base64 strings.
//hashes are taken each bank
//information is stored on disk in JSON format
func (s *SaveFile) Save(data [][]byte) error {
s.NoOfBanks = len(data)
s.Banks = make([]string, s.NoOfBanks)
s.BankHashes = make([]uint32, s.NoOfBanks)
s.LastSaved = fmt.Sprint(time.Now().Format(time.UnixDate))
log.Println("Saving RAM to", s.Path)
for i, bank := range data {
//take crc32 hash of bank
s.BankHashes[i] = crc32.ChecksumIEEE(bank)
//compress
bankStr, err := s.DeflateBank(bank)
if err != nil {
return errors.New(fmt.Sprintln("Error attempting to compress bank %d (%v)", i, err))
}
log.Printf("--> Storing bank %d (Compression ratio: %.1f%%)", i, 100.00-((float32(len(bankStr))/float32(len(bank)))*100))
s.Banks[i] = bankStr
}
//serialize to JSON
js, err := json.Marshal(&s)
if err != nil {
return errors.New(fmt.Sprintln("Error attempting to parse into JSON", err))
}
log.Println("Save file", s.Path, "size is", len(js), "bytes")
//write to disk
return ioutil.WriteFile(s.Path, js, 0755)
}
示例12: setCodeAndBody
func setCodeAndBody(w Response, code int, body interface{}) {
var contentType string
var data []byte
var err error
if jsonMap, ok := body.(map[string]interface{}); ok {
data, err = json.Marshal(jsonMap)
if err != nil {
w.ServerError("json marshal: ", err)
http.Error(w, fmt.Sprintln("Server Error: unexpected Ok body type"), 500)
return
}
contentType = "application/json; charset=utf-8"
} else if str, ok := body.(string); ok {
contentType = "text/plain; charset=utf-8"
data = []byte(str)
} else {
log.Printf("ERROR: unexpected Ok body type: %T\n", body)
http.Error(w, fmt.Sprintln("Server Error: unexpected Ok body type"), 500)
return
}
w.Header().Set("Content-Type", contentType)
w.WriteHeader(code)
w.Write(data)
// log.Println("setCodeAndBody:", code, contentType, body)
log.Println(" HTTP", code, ",", contentType, ",", len(data), "bytes")
}
示例13: graphiteWorker
func graphiteWorker(lCh chan string, gCh chan string, wg *sync.WaitGroup, host string, port uint16) {
defer wg.Done()
var (
err error
)
graphite := Graphite{Host: host, Port: port}
err = graphite.connect()
for err != nil {
lCh <- fmt.Sprintf("Connect Failure: Graphite has failed to connect, attempting reconnect in %d seconds.", 15)
time.Sleep(time.Second * 15)
err = graphite.connect()
}
for m := range gCh {
lCh <- "Sending Metric: " + m
err = graphite.sendMetric(m)
for err != nil {
lCh <- fmt.Sprintln("SendMetric Failure: Metric has failed to send, attempting to reconnect.")
err = graphite.connect()
if err != nil {
lCh <- fmt.Sprintln("Connect Failure: Graphite has failed to connect.")
lCh <- fmt.Sprintf("Connect Failure: Re-queuing metric and attempting reconnect in %d seconds.", 15)
gCh <- m
time.Sleep(time.Second * 15)
}
}
}
}
示例14: handleConnection
func handleConnection(conn net.Conn, msg_ch chan string, conn_ch chan net.Conn, rm_conn_ch chan net.Conn) {
conn.Write([]byte("What is your name?"))
data := make([]byte, 512)
_, err := conn.Read(data)
if err != nil {
fmt.Println(err)
conn.Close()
fmt.Println("user disconnected")
return
}
name := string(data)
msg_ch <- fmt.Sprintln(name, "joined the server")
conn_ch <- conn
for {
data := make([]byte, 512)
_, err := conn.Read(data)
if err != nil {
fmt.Println(err)
conn.Close()
fmt.Println(name, "disconnected")
rm_conn_ch <- conn
msg_ch <- string(name + " disconnected")
return
}
fmt.Println(name, ": ", string(data))
msg_ch <- fmt.Sprintln(name, ":", string(data))
}
}
示例15: Log
func (s *syslogBackend) Log(e *Event) {
if e.IsUp() {
s.writer.Info(fmt.Sprintln(e.Check.Key, btos(e.IsUp()), e.Duration))
} else {
s.writer.Err(fmt.Sprintln(e.Check.Key, btos(e.IsUp()), e.Duration))
}
}