vitess.io/vitess@v0.16.2/go/vt/callinfo/plugin_mysql.go (about)

     1  /*
     2  Copyright 2019 The Vitess Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package callinfo
    18  
    19  // This file implements the CallInfo interface for Mysql contexts.
    20  
    21  import (
    22  	"fmt"
    23  	"html/template"
    24  
    25  	"context"
    26  
    27  	"vitess.io/vitess/go/mysql"
    28  )
    29  
    30  // MysqlCallInfo returns an augmented context with a CallInfo structure,
    31  // only for Mysql contexts.
    32  func MysqlCallInfo(ctx context.Context, c *mysql.Conn) context.Context {
    33  	return NewContext(ctx, &mysqlCallInfoImpl{
    34  		remoteAddr: c.RemoteAddr().String(),
    35  		user:       c.User,
    36  	})
    37  }
    38  
    39  type mysqlCallInfoImpl struct {
    40  	remoteAddr string
    41  	user       string
    42  }
    43  
    44  func (mci *mysqlCallInfoImpl) RemoteAddr() string {
    45  	return mci.remoteAddr
    46  }
    47  
    48  func (mci *mysqlCallInfoImpl) Username() string {
    49  	return mci.user
    50  }
    51  
    52  func (mci *mysqlCallInfoImpl) Text() string {
    53  	return fmt.Sprintf("%s@%s(Mysql)", mci.user, mci.remoteAddr)
    54  }
    55  
    56  func (mci *mysqlCallInfoImpl) HTML() template.HTML {
    57  	return template.HTML("<b>MySQL User:</b> " + mci.user + " <b>Remote Addr:<b> " + mci.remoteAddr)
    58  }