<template>
  <div>
    <pre class="code language-go line-numbers" v-html="html"></pre>
    <el-button ref="btnCopy" type="info" style="position: absolute; top: 20px; right: 10px;">复制</el-button>
  </div>
</template>

<script>

import Prism from 'prismjs';
import 'prismjs/components/prism-go';
import FpCodeMixin from './FpCodeMixin';

export default {
  name: "FpCodeGo",
  mixins: [FpCodeMixin],
  computed: {
    html() {
      return Prism.highlight(this.code(), Prism.languages.go, 'go');
    }
  },
  methods: {
    code() {
      let c1 = this.json() || '    # 暂未指定任何动态参数\n'
      let c = `package main

import (
	"fmt"
	"github.com/psoho/fastposter-client-go/fastposter"
)

func main() {

	// 创建海报客户端
	client := fastposter.Client("${this.token}")

	// 设置参数
	params := map[string]interface{}${c1}

	// 生成海报
	poster, err := client.BuildPoster("${this.posterId}", params, "png")
	if err != nil {
		fmt.Println("Error:", err)
		return
	}

	poster.Save()
}
`;
      return c;
    }
  }
}
</script>

<style scoped>

.code {
  text-align: left;
  overflow: auto;
  user-select: text;
  cursor: text;
  height: 500px;
  font-size: 13px;
}

</style>