💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
[TOC] ## 示例 ### 音乐播放器适配 <details> <summary>main.go</summary> ``` package main import "fmt" // 播放接口 type Player interface { PlayMusic() } // 音乐播放器 type MusicPlayer struct { Src string } func (p MusicPlayer) PlayMusic() { fmt.Println("play music: " + p.Src) } // 游戏音乐播放器 type GameSoundPlayer struct { Src string } func (p GameSoundPlayer) PlaySound() { fmt.Println("play sound: " + p.Src) } // 使游戏音乐播放器适配音乐播放器 type GameSoundPlayerAdapter struct{ SoundPlayer GameSoundPlayer } func (g GameSoundPlayerAdapter) PlayMusic(){ g.SoundPlayer.PlaySound() } func main() { player :=GameSoundPlayer{Src:"game.mp3"} playerApater := GameSoundPlayerAdapter {SoundPlayer:player} play(playerApater) } func play(player Player) { player.PlayMusic() } ``` </details> <br /> 输出 ``` play sound: game.mp3 ```