vitess.io/vitess@v0.16.2/go/vt/vttablet/endtoend/framework/debugschema.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 framework
    18  
    19  import (
    20  	"encoding/json"
    21  	"fmt"
    22  	"net/http"
    23  )
    24  
    25  // Table is a subset of schema.Table.
    26  // TODO(sougou): I'm getting a json parsing error
    27  // on the 'Default' field of schema.TabletColumn. Otherwise,
    28  // we should just be able to decode the json output into a schema.Table.
    29  type Table struct {
    30  	Name    string
    31  	Columns []TableColumn
    32  	Type    int
    33  }
    34  
    35  // TableColumn contains info about a table's column.
    36  type TableColumn struct {
    37  	Name     string
    38  	Category int
    39  	IsAuto   bool
    40  }
    41  
    42  // DebugSchema parses /debug/schema and returns
    43  // a map of the tables keyed by the table name.
    44  func DebugSchema() map[string]Table {
    45  	out := make(map[string]Table)
    46  	var list []Table
    47  	response, err := http.Get(fmt.Sprintf("%s/debug/schema", ServerAddress))
    48  	if err != nil {
    49  		return out
    50  	}
    51  	defer response.Body.Close()
    52  	_ = json.NewDecoder(response.Body).Decode(&list)
    53  	for _, table := range list {
    54  		out[table.Name] = table
    55  	}
    56  	return out
    57  }